sparse array
2022年5月1日小于 1 分钟
sparse array
Question
What does the code snippet to the right output by console.log
?
Snippet
const arr = [1,,,2]
// forEach
arr.forEach(i => console.log(i))
// map
console.log(arr.map(i => i * 2))
// for ... of
for (const i of arr) {
console.log(i)
}
// spread
console.log([...arr])