3 回答

TA貢獻2036條經(jīng)驗 獲得超8個贊
.push
.push
:
>>> a.push(...b)
.apply
>>> a.push.apply(a, b)
>>> Array.prototype.push.apply(a,b)
b
b

TA貢獻1921條經(jīng)驗 獲得超9個贊
a.push(...b)
Array.concat
.
var a = [1, 2, 3];a = a.concat([5, 4, 3]);
const a = [1, 2, 3];const b = [...a, 5, 4, 3];

TA貢獻2016條經(jīng)驗 獲得超9個贊
.apply
Array.prototype.extend = function (other_array) { /* You should include a test to check whether other_array really is an array */ other_array.forEach(function(v) {this.push(v)}, this);}
var a = [1,2,3];var b = [5,4,3];a.extend(b);
.apply
Array.push.apply
Array.slice.apply
.
forEach
.apply
Array.prototype.extend = function (array) { array.forEach(this.push, this);}
Array.prototype.forEach
forEach
添加回答
舉報