How to flatten array in jQuery?

后端 未结 10 766
感动是毒
感动是毒 2020-12-03 02:34

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]
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 03:07

    var a = [1, 2, [3, 4], [5, [6, [7, 8]]]];
    var b = [];
    
    function flatten(e,b){
        if(typeof e.length != "undefined")
        {
            for (var i=0;i

    The flatten function should do it, and this doesn't require jQuery. Just copy all of this into Firebug and run it.

提交回复
热议问题