JavaScript array of arrays USES strings as subscripts for arrays

  • 2020-03-29 23:50:41
  • OfStack

Array inherits from Object. It has all the functionality and features of Object. Here is the case of Object:
New: var  Object  =     New  The Object ();
Added: object[strIndex]  =   The value; (strIndex string)
Delete: delete  Object [strIndex];
Traversal: for  (  Var  StrObjIndex  In  Object) object [strObjIndex];  
As follows:


var obj = new Object();
    obj["first"] = "my";
    obj["second"] = "name";
    obj["third"] = "is";
    obj["fourth"] = "chenssy";

Since Array inherits Object, Array can also be subscripted with a string:
The following


var array = new Array();
    array["first"] = "my";
    array["second"] = "name";
    array["third"] = "is";
    array["fourth"] = "chenssy";

For the traversal of an array number, we use a for loop. But the for loop is not in this form:


 for(int i =  0;i<arrray.length;i++)
 

We can use the for/in loop to iterate over the array. The for/in loop temporarily assigns the index of an array to a variable:


1for(variable in array)

In the first loop, the variable variable is assigned to the lower value of the first element of the array. In the second loop, the variable variable is assigned to the lower value of the second element of the array. And so on...
For the array array above, the for/in loop traverses:


for(key in array)


Related articles: