Here’s Why Mapping a Constructed Array in JavaScript Doesn’t Work

And How To Do It Correctly

Shawn Reisner
ITNEXT
Published in
4 min readJun 15, 2018

--

Scenario

For the sake of demonstration, suppose you need to generate an array of numbers from 0 to 99. How might you do this? Here’s one option:

const arr = [];for (let i = 0; i < 100; i++) {
arr[i] = i;
}

--

--