consider that I declare two variables like this (executed in REPL, with node v7.7.2), which I expect to be arrays:
var x = Array(4) var y = Array.from({length: 4})
then the following should work identically, but it is not:
x.map(Math.random) [ , , , ] y.map(Math.random) [ 0.46597917021676816, 0.3348459056304458, 0.2913995519428412, 0.8683430009997699 ]
when searching, it seems that x and y are both identical:
> typeof x 'object' > typeof y 'object' > Array.isArray(x) true > Array.isArray(y) true > x.length 4 > y.length 4 > typeof x[0] 'undefined' > typeof y[0] 'undefined'
so why the difference?
ekkis
source share