Remove empty strings from array while keeping record Without Loop?

后端 未结 7 1625
臣服心动
臣服心动 2020-11-28 20:55

This question was asked here: Remove empty strings from array while keeping record of indexes with non empty strings

If you\'d notice the given as @Baz layed it out;

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 21:34

    You can use lodash's method, it works for string, number and boolean type

    _.compact([0, 1, false, 2, '', 3]);
    // => [1, 2, 3]
    

    https://lodash.com/docs/4.17.15#compact

提交回复
热议问题