functional way to iterate over range (ES6/7) [duplicate]

One can create an empty array, fill it (otherwise map will skip it) and then map indexes to values:

Array(8).fill(0).map((_, i) => i * i);

Leave a Comment