我正在尝试使用 Array.prototype.push.apply 合并两个列表。
c = Array.prototype.push.apply(a, b);
但是,当第二个数组为 []
时,这不会合并数组。
例如,如果
a = ['x', 'y', 'z']
b = []
c
将是 3
为什么会发生这种情况?
[]
不应该像任何数组一样对待吗?
最佳答案
只需使用Array.prototype.concat:
c = a.concat(b);
关于javascript - Array.prototype.push.apply 意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34309099/