javascript
var arr = ['a','b','c'];
console.log("for loop");
for( var i=0; i< arr.length; i++){
console.log(arr[i]);
}
console.log("for in loop");
arr.name = 'testname';
for (var i in arr) {
if (arr.hasOwnProperty(i)) {
console.log("i: "+i +" typeof: "+ (typeof i)); //i是字符串而不是数字
console.log(arr[i]);
}else{
console.log('this is inherit property');
}
}
console.log("for of loop");
for (var i of arr) {
console.log(i);
}
原文链接:https://www.f2er.com/note/422551.html