I want to generate an empty array of a given length and the populate it with some numbers. One way to generate an array with four sequential numerical elements is :
var x = Array.apply(null, {length: 4}).map(function(item, index){return index;})
But when I saw Array.apply(null, {length: 4}) I thought I could instead replace it with new Array(4) but that is not the case. Doing a quick test yields the following:
>> console.log((new Array(4)))
<< [ <4 empty items> ]
>> console.log(Array.apply(null, {length: 4}))
<< [ undefined, undefined, undefined, undefined ]
Which means I can .map the latter but not the former.
What is the difference then between new Array and Array.apply(null, {}) which I thought were both creating an array object with given length?