The Array object in JavaScript is a dynamic Array, a Stack, or a Dictionary. It is a dynamic Array because data is dynamically added;
The Code is as follows:
Var myarr = new Array ();
Myarr [0] = 1;
Myarr [1] = 2;
Myarr [2] = 3;
Myarr [3] = 23;
Myarr [4] = 11;
Use for traversal;
It is a dictionary object because it can be accessed as a key value:
The Code is as follows:
Var dictionary = new Array ();
Dictionary ["Xie longbao"] = "xielongbao ";
Dictionary ["Zhou baucui"] = "zhoubaocui ";
Dictionary ["Xie Xiaoyue"] = "xiexiaoyue ";
Alert (dictionary ["Xie longbao"]);
Alert (dictionary. Xie longbao );
For (var key in dictionary ){
Alert ("key:" + key + "value:" + dictionary [key]);
}
Use for-in for traversal. The array is a special case of dic. The array key is an integer and the dic key is a string. Therefore, the array can also be traversed using for-in; in addition, because the object members in js also exist in the form of keys, we can use for-in to view the js object members;
Simplified Syntax of arrays in js:
Var arr = [1, 2, 3, 4];
Simplified Writing of dic in js:
Var arrdic = {"jim": 30, "tom": 20 };
This is often used for interaction with the server, because the data transmitted from the server is in json format, that is, the key-value pairs in Javascript facilitate front-end operations;
It is a Stack because it has pop (), push (), and other methods for operating the stack;