I'm trying to use the underscore.js each
function to push each element of an array onto an existing array, in-place.
To do this, I assumed I could use the push
array method, rather than the usual anonymous function passed to each
, provided that I passed a context object as the 3rd argument to each
:
> var a = [1,2,3]
> var b = []
> _.each(a, b.push, b)
I'd expect b
to now be [1,2,3]
, but it is actually:
Array [ 1, 0, Array[3], 2, 1, Array[3], 3, 2, Array[3] ]
What is going on?