How to initialize an array’s length in JavaScript?
Array(5) gives you an array with length 5 but no values, hence you can’t iterate over it. Array.apply(null, Array(5)).map(function () {}) gives you an array with length 5 and undefined as values, now it can be iterated over. Array.apply(null, Array(5)).map(function (x, i) { return i; }) gives you an array with length 5 and values … Read more