for-in遍历
for-in是为遍历对象而设计的,不适用于遍历数组。
遍历数组的缺点:数组的下标index值是数字,for-in遍历的index值"0","1","2"等是字符串
for (var index in arr){
console.log(arr[index]);
console.log(index);
}
2023-02-28 15:22:33
for-in是为遍历对象而设计的,不适用于遍历数组。
遍历数组的缺点:数组的下标index值是数字,for-in遍历的index值"0","1","2"等是字符串
for (var index in arr){
console.log(arr[index]);
console.log(index);
}