Article Introduction: the array in JavaScript. |
Array is a commonly used type in JavaScript, and arrays in JavaScript are quite different from arrays in other languages. The data types that are stored in an array in JavaScript are not necessarily the same, and the length of the array can be changed.
Here's a list of common operations for array:
a new array
To create a new array, you can use the method:
var obj = [' Zdy ', 22, ' Wuhan, Hubei ', ' Computer Science and technology '];//create an array variable
var obj1 = new Array (' Zdy ', 22, ' Hubei Wuhan ', ' Computer Science and Technology ');
var obj2 = new Array (4);
Obj2[0] = ' zdy ';
OBJ2[1] =;
OBJ2[2] = ' Hubei Wuhan ';
OBJ2[3] = ' Computer science and technology ';
The above way to create an array is actually equivalent, output:
alert (obj); Return to zdy,22, Hubei Wuhan, Computer Science and Technology
Alert (OBJ1); Return to zdy,22, Hubei Wuhan, Computer Science and Technology
Alert (OBJ2); Return to Zdy,22, Wuhan, Hubei, computer science and technology
The data types stored in the previous JavaScript array are not necessarily consistent, so we can also create the following array:
var obj3 = [
' Zdy ',
[1, ' 2 ', true],
{
name: ' Zdy ',
age:22, address
: ' Hubei Wuhan '
}
];
Look at the output below:
alert (obj3);//Return Zdy,1,2,true,[object Object]
alert (obj3[1][2]);//return True
alert (obj3[2].address);/Return to Wuhan, Hubei
[1] [2] [3] Next page