JavaScript for/in 语句 遍历数组内容

for-in遍历

for-in是为遍历对象而设计的,不适用于遍历数组。

遍历数组的缺点:数组的下标index值是数字,for-in遍历的index值"0","1","2"等是字符串

for (var index in arr){
    console.log(arr[index]);
    console.log(index);
}
posted @ 2019-03-15 08:48  你的老张  阅读(1809)  评论(0编辑  收藏  举报