js 数组合并
Posted lijun8637
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 数组合并相关的知识,希望对你有一定的参考价值。
1、循环插入
for (var i=0; i < b.length; i++) {
a.push( b[i] );
}
2、 a.push.apply(a,b);
b.unshift.apply( b, a );
例如: a.push.apply(a,[4,5,6]); 等同于 a.push(4,5,6);
3、 let c = a.concat( b );
4、ES5// `b` o
a; // [1,2,3,4,5,6,7,8,9,"foo","bar","baz","bam","bun","fun"]
// or `a` into `b`:
b = a.reduceRight( function(coll,item){
coll.unshift( item );
return coll;
}, b );
b; // [1,2,3,4,5,6,7,8,9,"foo","bar","baz","bam","bun","fun"]
5、避免数组最大长度限制
function combineInto(a,b) {
for (let i=0; i < a.length; i=i+5000) {
b.unshift.apply( b, a.slice( i, i+5000 ) );
}
}
相关文章:http://www.cnblogs.com/Being-a-runner-up/p/5627166.html
以上是关于js 数组合并的主要内容,如果未能解决你的问题,请参考以下文章