Imagine you want to generate a brand-new array of 5 backpack slot numbers ([0, 1, 2, 3, 4]) or 50 level numbers without typing every single number by hand.
You can use Array.from() to build a new array from scratch. You give it two arguments:
1.
An object specifying the desired size: { length: 5 }
2.
A callback function (element, index) => ... that returns the value to place at each index:
↗️
Loading editor...
↶
↷
Because we are creating a brand-new array from { length: 5 }, the first parameter (element) is undefined, while the second parameter (index) counts from 0 to 4.