We know that Object is using the new keyword or literal notation declared and created.
So the type of application can also be declared with --Array created in a similar way.
A, new keyword to create an array: new Array ();
var colors = new Array(); console.log(colors); console.log(colors.length); colors[0] = '1'; colors[1] = 2; console.log(colors);
Second, the length of the display declares the array, such as new Array (10);
var colors2 = new Array(20); console.log(colors2); console.log(colors2.length); colors2[20] = '2'; the console.log (colors2); // before blank 20 is twenty-one 2 the console.log (colors2 [20 is]); // twenty-one 2 the console.log (colors2.length); // The total length is 21
Third, Array () method was added directly to the initial value, such as new Array (1,2,3);
var colors3 = new Array(1, '2', 3.0); console.log(colors3); console.log(colors3.length); colors3[3] = colors2; console.log(colors3); console.log(colors3.length);
Note: Representation II and III require separate areas, when we use the brackets Array () is only one in number, it indicates that the second method, the array length digital representation; when new Array () is placed 3 ' 'string, said three methods, the initial length of the array 1.
var CC = new new the Array (3); // declare an initial array of length 3 var dd = new new the Array ( '3'); // declare an array of a first length and a value of 3 console .log (cc); console.log(dd);
Fourth, the proof can have omit the new keyword Array, Array (), Array (3), Array ( '3') are legal
Five, Array also has a literal representation
var colors4 = [ 'Red', 2, 4.0]; // create an array of length 3 of the console.log (colors4); var colors5 = []; // array of length 0 colors5 [0] = '1' ; // Add a colors5 [0] =. 3; // modify first the console.log (colors5); // [. 3] the console.log (colors5.length);