Home > Web Front-end > JS Tutorial > Instructions for using Array objects in JavaScript_javascript tips

Instructions for using Array objects in JavaScript_javascript tips

WBOY
Release: 2016-05-16 18:11:47
Original
1245 people have browsed it

It is said to be a dynamic array because data is added dynamically;

Copy code 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 to traverse;
It is said to be a dictionary object because it can be accessed in the form of key value:
Copy code The code is as follows:

var dictionary = new Array();
dictionary["Xie Longbao" ] = "xielongbao";
dictionary["Zhou Baocui"] = "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 to traverse. Arrays are a special case of dic. The keys of the array are integers and the keys of dic are strings, so the array can also be traversed using for-in; in addition, because the members of objects in js are also based on keys exists in the form, so we can use for-in to view the members of the js object;

Simplified writing of arrays in js:

var arr = [1, 2, 3, 4];
Simplified writing of dic in js:
var arrdic = { "jim": 30, "tom": 20 };
This is very commonly used in interactions with the server, because now it is passed from the server The data that comes over are all in json format, that is, the key-value pair format in Javascript is convenient for front-end operations;
It is called Stack because it has pop(), push() and other methods to operate the stack;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template