remove an empty string from array of strings - JQuery

后端 未结 5 1742
无人及你
无人及你 2020-12-13 18:00

I have an array [\"Lorem\", \"\", \"ipsum\"]. I would like to remove the empty string from this array and get [\"Lorem\", \"ipsum\"].

Is th

5条回答
  •  半阙折子戏
    2020-12-13 18:46

    If you use Javascript 1.6 (probably wont work on IE8 or less) you can use

    arr.filter(Boolean) //filters all non-true values
    

    eg.

    console.log([0, 1, false, "", undefined, null, "Lorem"].filter(Boolean));
    // [1, "Lorem"]

提交回复
热议问题