Remove all falsy values from an array

后端 未结 22 3279
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 07:21

I would like to remove all falsy values from an array. Falsy values in JavaScript are false, null, 0, \"\", undefined, and NaN.



        
22条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 07:46

    Using this simple filter will do:

    array.filter(Boolean)

    You can read more about Boolean here

提交回复
热议问题