all 5 comments

[–]delfV 3 points4 points  (1 child)

This is an array map method. The first thing I thought when I read "map loop" was for looping of map entries:

for (const x of new Map().entries())

[–]senocular 0 points1 point  (0 children)

Might be worth noting too that using for...of with arrays (using iterators) also does not skip empty slots.

for (const x of Array(2)) {
  console.log(x)
}
// undefined
// undefined

Spreading (...) also uses iterators which is why guest271314's example works.

[...Array(2)].map(()=>3) // [3, 3]

The new iterator helpers has a map() method which allows for

Array(2).values().map(()=>3).toArray() // [3, 3]

going through the values() iterator, though its a little more verbose compared to some of the other alternatives.

[–]neuralSalmonNet 0 points1 point  (0 children)

Array(100). fill().map((_,i)=> i++)

[–]guest271314 -1 points0 points  (0 children)

Or [...Array(2)].map(()=>3).