Array is inherited from the Object. It has all the functions and features of the Object. The following describes the situation of objects:
New: var object = new Object ();
Added: object [strIndex] = value; (strIndex is string)
Delete: delete object [strIndex];
Traversal: for (var strObjIndex in object) object [strObjIndex];
As follows:
Copy codeThe Code is as follows:
Var obj = new Object ();
Obj ["first"] = "my ";
Obj ["second"] = "name ";
Obj ["third"] = "is ";
Obj ["fourth"] = "chenssy ";
Because Array inherits objects, Array can also use strings as the underlying Object of the Array:
As follows:
Copy codeThe Code is as follows:
Var array = new Array ();
Array ["first"] = "my ";
Array ["second"] = "name ";
Array ["third"] = "is ";
Array ["fourth"] = "chenssy ";
For the traversal of array numbers, we use the for loop statement. However, this for loop is not in this form:
Copy codeThe Code is as follows:
For (int I = 0; I <arrray. length; I ++)
We can use the for/in loop to traverse the array. The for/in loop temporarily assigns the subscript of an array to a variable:
Copy codeThe Code is as follows:
1for (variable in array)
In the first loop, the variable is assigned the lower value of the first element of the array. In the second loop, the variable will be assigned the lower value of the second element of the array, and so on .......
For the array above, use the for/in loop traversal:
Copy codeThe Code is as follows:
For (key in array)