Remove empty strings from array while keeping record Without Loop?

后端 未结 7 1606
臣服心动
臣服心动 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:30

    var arr = ["I", "am", "", "still", "here", "", "man"]
    // arr = ["I", "am", "", "still", "here", "", "man"]
    arr = arr.filter(Boolean)
    // arr = ["I", "am", "still", "here", "man"]
    

    filter documentation


    // arr = ["I", "am", "", "still", "here", "", "man"]
    arr = arr.filter(v=>v!='');
    // arr = ["I", "am", "still", "here", "man"]
    

    Arrow functions documentation

提交回复
热议问题