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 commentsSpeak rationally on civilized internet, please comply with News Comment Service Agreement