for in循环遍历
let arr = [1, 2, 3, 4, 4, 3], str = ‘‘ for (const val in arr) { str += val + ‘ ‘ } console.log(str); // 0 1 2 3 4 5
for of循环遍历对象(数组)
let arr = [1, 2, 3, 4, 4, 3], str = ‘‘ for (const val of arr) { str += val + ‘ ‘ } console.log(str); // 1 2 3 4 4 3
forEach 循环数组
let arr = [1, 2] arr.forEach((item, index) => { console.log(item,index); // 1 0 // 2 1 });
原文地址:https://www.cnblogs.com/cap-rq/p/11769708.html
时间: 2024-10-13 03:00:40