I'm trying to push multiple elements as one array, but getting error(我试图将多个元素作为一个数组推送,但是会出错)
> a = []
[]
> a.push.apply(null, [1,2])
TypeError: Array.prototype.push called on null or undefined
I'm trying to do similar stuff that I'd do in ruby, I was thinking that apply
is something like *
.(我正在尝试做类似我在ruby中做的事情,我认为apply
就像*
。)
>> a = []
=> []
>> a.push(*[1,2])
=> [1, 2]
ask by evfwcqcg translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…