Merge multiple arrays to one array in jquery

a 夏天 提交于 2019-12-04 12:36:21

use .concat

and to apply it for multiple array like below

var multipleArrays = [[1,2], [3,4], [5,6]];

var flatArray = [].concat.apply([], multipleArrays); 
// [1, 2, 3, 4, 5, 6]

// Using the Spread syntax
var flatArray2 = Array.prototype.concat(...multipleArrays);
// [1, 2, 3, 4, 5, 6]

array1.concat(array2) in plain javascript

You can just push all values from one to another

var a = [1,2,3]
var b = [2,3,4,5]
a.push.apply(a, b)
console.log(a);// [1, 2, 3, 2, 3, 4, 5]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!