Angular - Filter to remove blank strings from array

后端 未结 4 518
甜味超标
甜味超标 2021-01-16 01:46

I have an object of arrays... The array can contain blanks, how can i create an ANgular filter to remove the blanks to determine the length of the array?

$sc         


        
4条回答
  •  温柔的废话
    2021-01-16 02:30

    The other answers didn't work for me and angular-filter doesn't have any specific abilities for this case, but the following worked in my Angular app. No custom filter needed.

    arr = ["", "foo", "bar"];
    arr.filter(Boolean);
    

    Browser compatability: http://kangax.github.io/compat-table/es5/#Array.prototype.filter

提交回复
热议问题