遍历数组的方法
发布时间
阅读量:
阅读量
示例中所展示的数组为:
var arr = [
{ id: 1, name: '王昭君' },
{ id: 2, name: '安琪拉' },
{ id: 3, name: '鲁班七号' },
];
var nums = [1, 2, 3, 4, 5];
1. 普通for循环;
for (let i = 0; i < arr.length; i++) {
console.log(arr[i], i);
}
2,forEach循环;
arr.forEach((ele, index) => {
console.log(ele, index);
});
3、for…in,(主要是用来遍历对象,不建议遍历数组)
全部评论 (0)
还没有任何评论哟~
