Remove empty elements from an array in Javascript

后端 未结 30 2524
无人共我
无人共我 2020-11-21 09:53

How do I remove empty elements from an array in JavaScript?

Is there a straightforward way, or do I need to loop through it and remove them manually?

30条回答
  •  梦如初夏
    2020-11-21 10:31

    What about that:

    js> [1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,].filter(String).join(',')
    1,2,3,3,0,4,4,5,6
    

提交回复
热议问题