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

js遍历数组的两种方法

WBOY
Release: 2016-06-01 09:55:06
Original
1434 people have browsed it

JS数组的遍历方法有两种:

第一种:一般的for循环,例如:

<code>var a = new Array("first", "second", "third") 
for(var i = 0;i </code>
Copy after login

输出的结果:fitst,second,third

 

第二种:用for...in 这种遍历的方式,例如:

<code>var arr = new Array("first", "second", "third") 
for(var item in arr) {
   document.write(arr[item]+",");
}</code>
Copy after login

输出的结果:fitst,second,third

 

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!