Use Array Fill to Create Magic

How to use Array.fill() to your fill.

We have seen examples of how to use Array.fill() to quickly fill data in an array. But, can we do more?

Yes..! You can generate array with sequential numbers. Use Array.fill() to line up your number array in sequence.

const nums = new Array(10).fill().map((val, index) => index + 1);
console.log(nums);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Note technically an array.fill(), but you get it :)

comments powered by Disqus