As described here, a quick way to append array b to array a in javascript is a.push.apply(a, b)
.
You'll note that the object a is used twice. Really we just want the push
function, and b.push.apply(a, b)
accomplishes exactly the same thing -- the first argument of apply supplies the this
for the applied function.
I thought it might make more sense to directly use the methods of the Array object: Array.push.apply(a, b)
. But this doesn't work!
I'm curious why not, and if there's a better way to accomplish my goal. (Applying the push
function without needing to invoke a specific array twice.)