1.concat()方法
代码:
var a=[12,34,4,55,"hello",Boolean];
var b=["world",Number]
var c=a.concat(b)
console.log(a)
console.log(c)
结果:
2.Arrat.prototype.push.apply(arr1,arr2)
代码:
var a=[12,34,4,55,"hello",Boolean];
var b=["world",Number]
var c=a.concat(b)
Array.prototype.push.apply(a,b);
console.log(a)
结果:
3.arr1.push(…arr2) …arr2为扩展运算符
代码:
var a=[12,34,4,55,"hello",Boolean];
var b=["world",Number]
var c=a.concat(b)
a.push(...b)
console.log(a)
结果:
[…arr1,…arr2] …arr1,…arr2为扩展运算符
代码:
var a=[12,34,4,55,"hello",Boolean];
var b=["world",Number]
var c=a.concat(b)
var c=[...a,...b]
console.log(c)
结果:
5.push()方法+for()
代码:
var a=[12,34,4,55,"hello",Boolean];
var b=["world",Number]
for(var i=0;i<a.length;i++){
b.push(a[i])
}
console.log(b)
结果: