Home > Web Front-end > JS Tutorial > body text

javaScript array (array) method of using strings as array subscripts_Basic knowledge

WBOY
Release: 2016-05-16 17:14:13
Original
2128 people have browsed it

Array is inherited from Object. It has all the functions and characteristics of Object. The following is the case of Object:
New: var object = new Object();
Add: object[strIndex] = value; (strIndex is string)
Delete: delete object[strIndex];
Traversal: for (var strObjIndex in object) object[strObjIndex];
is as follows:

Copy code The code is as follows:

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

Because Array inherits Object, Array can also use strings as array subscripts:
As follows

Copy code The code is as follows:

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

For traversing array numbers, we use a for loop statement. But this for loop is not in this form:

Copy code The code is as follows:

for(int i = 0;i

We can use for/in loop to traverse the array. The for/in loop temporarily assigns the subscript of an array to a variable:

Copy code The code is as follows:

1for(variable in array)

In the first loop, the variable variable will be assigned the subscript value of the first element of the array; in the second loop, the variable variable will be assigned the subscript value of the second element of the array array. scalar value; and so on....
For the above array, use for/in loop to traverse:

Copy code The code is as follows:

for(key in array)
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!