Arrays

What is an Array?

An array is simply a collection of values. It’s a special variable, which can hold more than one value at a time.

For example, consider an array called fruits, which would contain values like apple, orange, mango etc… all together in a single variable.

How to create one

The following statements show how to create arrays in two different ways but the end result is the same.

Syntax:

var arrayName = new Array(element0, element1, ..., elementN);
var arrayName = Array(element0, element1, ..., elementN);
var arrayName = [element0, element1, ..., elementN];

Example: #Can’t find image