JavaScript for 循环

JavaScript About 430 words

代码

const arr = [3, 5, 7];
arr.foo = 'hello';

for (const i in arr) {
  console.log(i); // "0", "1", "2", "foo"
}

for (const i of arr) {
  console.log(i); // 3, 5, 7, undefined
}


arr.forEach((e) => {
    console.log(e); // 3, 5, 7, undefined
})

文档

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

Views: 748 · Posted: 2023-01-18

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh