如何在jQuery中展平数组? [英] How to flatten array in jQuery?

查看:51
本文介绍了如何在jQuery中展平数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 jQuery 中简单地展平数组?我有:

How to simply flatten array in jQuery? I have:

[1, 2, [3, 4], [5, 6], 7]

我想要:

[1, 2, 3, 4, 5, 6, 7]

推荐答案

您可以使用 jQuery.map,如果你已经加载了 jQuery 库,这是要走的路.

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;
});

退货

[1, 2, 3, 4, 5, 6, 7]

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

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