i

JavaScript

Creating an Array

Arrays are data structures that contain a group of elements. In general, all the elements in the array will be of the same data type.In JavaScript, the data type of an array is Object.

Creating an array:

Declaring/defining an array is the same as declaring/defining any other variable.

Example:

var fruits = [“Apple”, “Banana”, “Orange”];

Array can span multiple lines. It does not consider spaces and line breaks.

var fruits = [“Apple”,

                    “Banana”,

                    “Orange”];

In JavaScript, an array can also be created using the newkeyword.

var fruits = new Array (“Apple”, “Banana”, “Orange”);

Though both the above examples do the same; it is recommended not to use newsince the other way is more simple, readable, and takes lesser time for execution.