Consider the code
const arr = [];
[1].map(arr.push)
This gives TypeError: can\'t convert undefined to object
(on Firefox at le
That's because arr.push
is just a reference to a generic function not bound to arr
.
Therefore, when called as a callback, it doesn't know on which array you want to push
var func = [].push;
func(123); // TypeError: can't convert undefined to object
This will work, but multiple arguments will be passed to push
, which you probably don't want
const arr = [];
[1, "a"].map(arr.push.bind(arr)); // [ 3, 6 ]
arr; /* [ 1, 0, [1, "a"],
"a", 1, [1, "a"] ] */
So just use your [1].map(v => arr.push(v))