Array.from second argument
7 feb 2022Today I learned that Array.from method takes a function as second argument that will be used to fill the created array.
const array = Array.from({ length: 5 }, (_value, index) => index);
// [ 0, 1, 2, 3, 4 ]
Instead of usually
const array = Array.from({ length: 5 }).map((_value, index) => index);
// [ 0, 1, 2, 3, 4 ]