javascript array initialization code example

Example 1: javascript array

//create an array like so:
var colors = ["red","blue","green"];

//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
    console.log(colors[i]);
}

Example 2: javascript declare array

var array = []

Example 3: initialize javascript array variable

var arrayName = new Array();
var arrayName = new Array(Number length);
var arrayName = new Array(element1, element2, element3);

Example 4: how to initialize an array in javascript

var array_name = [item1, item2, ...];

Tags:

Java Example