在jQuery中将多个数组合并到一个数组 [英] Merge multiple arrays to one array in jquery

查看:1189
本文介绍了在jQuery中将多个数组合并到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jquery将多个数组合并为一个数组.我知道我们可以使用jquery merge函数将两个数组合并为一个.我们可以遍历这些数组并将它们也加入一个数组.但是我只是想知道是否有其他方法可以在不使用任何循环的情况下实现这一目标.我正在处理大量数据.因此,我也可以期待任意数量的数组.我担心如果使用循环,可能会影响性能.请给我一些建议.提前致谢.

I am trying to merge my multiple arrays to one array using jquery. I know that we can merge two arrays to one using jquery merge function. And we can loop through those arrays and join them to one too. But I just wanted to know whether there is any other way to achieve this without using any loop. I am handling large number of datas. So I can expect any number of arrays too. I am worrying if we use a loop, it may affect the performance. Please give me some suggestions. Thanks in advance.

最亲切的问候 希贝什·维努

Kindest Regards Sibeesh Venu

推荐答案

使用.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]

这篇关于在jQuery中将多个数组合并到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆