1、对象遍历(for-in):
var obj = {
'0':'a',
'1':'b',
'2':'c'
};
// i遍历为key
for(var i in obj) {
console.log(i,":",obj[i]);
}
2、数组遍历(for-in)
var arr=["张三","李四","王五","赵六"];
// i遍历为下标
for (var i in arr){
console.log(i,":",arr[i]);
}
3、数组遍历(for-of)
var arr=["张三","李四","王五","赵六"];
// value遍历为元素
for (var value of arr){
console.log(value);
}
全部评论