Can anyone explain the next weird behavior?
This works:
const defaultSides = 10;
const stats = Array.apply(null, { length: defaultSides }).map(() => 100);
// Array [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
This doesn't:
const stats2 = new Array(defaultSides);
const res = stats2.map(() => 100);
console.log(res)
//Array [undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined]
I've already solved the problem using either Array.from or Array.of. However, I want to know what causes Javascript to still return me an undefined array after obviously having mapped through it in the second code block.