javascript - push multiple elements to array -
i'm trying force multiple elements 1 array, getting error
> = [] [] > a.push.apply(null, [1,2]) typeerror: array.prototype.push called on null or undefined i'm trying similar stuff i'd in ruby, thinking apply *.
>> = [] => [] >> a.push(*[1,2]) => [1, 2]
when using functions of objects apply or call, context parameter must object working on.
in case, need a.push.apply(a, [1,2]) (or more correctly array.prototype.push.apply(a, [1,2]))
javascript
No comments:
Post a Comment