将多个元素推送到数组
2022-08-29 23:19:19
我试图将多个元素作为一个数组推送,但收到错误:
> a = []
[]
> a.push.apply(null, [1,2])
TypeError: Array.prototype.push called on null or undefined
我正在尝试做类似的事情,就像我在ruby中所做的那样,我想这就像.apply
*
>> a = []
=> []
>> a.push(*[1,2])
=> [1, 2]