Home >Web Front-end >JS Tutorial >JS array traversal method for loop and for...in_javascript techniques

JS array traversal method for loop and for...in_javascript techniques

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:40:371443browse

There are two ways to traverse JS arrays:

The first type: general for loop, for example:

var a = new Array("first", "second", "third") 
for(var i = 0;i < a.length; i++) {
document.write(a[i]+",");
}

Output results: fitst, second, third

The first method: use for...in this traversal method, for example:

var arr = new Array("first", "second", "third") 
for(var item in arr) {
document.write(arr[item]+",");
}

Output results: fitst, second, third

Statement:
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