Code Highlights logo

Learn

Arrays

Create an Array

An array is a data structure that can hold multiple values of different types. We can create an array using the following methods:

Method 1: Array Literal

The simplest way to create an array is by using array literal notation. Simply enclose the elements inside square brackets [] and separate them with commas.

1let fruits = ["apple", "banana", "orange"];

Method 2: Array Constructor

Another way to create an array is by using the Array constructor.

1let numbers = new Array(1, 2, 3, 4, 5);

Instructions

1.

Declare a variable named myArray and assign it an empty array (array literal, without any elements).

Sign up to start coding

Already have an account?

Sign In

Course content