This call
[0].map(Array);
gives you the same result as if you wrote something like this:
[0].map(function (value, index, array) {
return Array(value, index, array);
})
Map function is calling Array function with three parameters: value of element, index of element and whole array. This call to Array
returns you array with 3 elements: value (number 0
), index (number 0
), whole array ([0]
).
And this new array is wrapped in the original Array, because you maped original element (number 0
) to new element (array of 3 elements)
Note: You might be used to using only the first parameter like in
array.map(function (a) { return a * a; });
or using just two to get also index
array.map(function (item, index) { return "index=" + index + ", value=" + item; });
But you need to remember that map
still provides 3 parameters you just ignore them in your callback function. That's also the reason why code like:
[0].map(String);
returns
["0"]
It's because String function care only about the first parameter and ignores other passed parameters.
If you call
String(11, "Some", "other", "ignored", "parameters")
you will still get
"11"