如何压平jQuery的阵列? [英] How to flatten array in jQuery?
本文介绍了如何压平jQuery的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何简单地压平jQuery的阵列?我有:
[1,2,[3,4],[5,6],7]
和我想要的:
[1,2,3,4,5,6,7]
解决方案
您可以使用 jQuery.map ,该是,如果你有jQuery库已经加载的路要走。
$。图([1,2,[3,4],[5,6],7],功能(N){
返回N;
});
返回
[1,2,3,4,5,6,7]
How to simply flatten array in jQuery? I have:
[1, 2, [3, 4], [5, 6], 7]
And I want:
[1, 2, 3, 4, 5, 6, 7]
解决方案
You can use jQuery.map, which is the way to go if you have the jQuery Library already loaded.
$.map( [1, 2, [3, 4], [5, 6], 7], function(n){
return n;
});
Returns
[1, 2, 3, 4, 5, 6, 7]
这篇关于如何压平jQuery的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文