remove an empty string from array of strings - JQuery

后端 未结 5 1654
无人及你
无人及你 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

    You may use filter :

    var newArray = oldArray.filter(function(v){return v!==''});
    

    The MDN has a workaround for IE8 compatibility. You might also use a good old loop if you're not going to use filter anywhere else, there's no problem with looping...

提交回复
热议问题