Blogger Information
Blog 33
fans 0
comment 1
visits 43074
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript中的for in循环的作用
萝卜温的博客
Original
1055 people have browsed it

JavaScript 的 for in 循环的主要作用是从对象中提取出属性名,然后通过数组形式访问对象属性,这样就能实现对象的遍历!例如

var obj = {name:"iphone", color: "黑色", price: 1000};
for(k in obj) {
    console.log(k);
    console.log(obj[k]);
}
//结果是:name iphone color 黑色 price 1000

这是很常用的循环结构,需要重新构造对象时经常用到!

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post