数组去除数组中为“假”的元素。
2020-12-28 本文已影响0人
陶菇凉
array.filter(Boolean)
Array.prototype.filter()方法用于过滤数组,返回一个符合特定操作的元素组成的数组。
array.filter((item) => {return Boolean(item)})
也就是说这样写的意思就是去除数组中为“假”的元素。
array.filter(Boolean)
Array.prototype.filter()方法用于过滤数组,返回一个符合特定操作的元素组成的数组。
array.filter((item) => {return Boolean(item)})
也就是说这样写的意思就是去除数组中为“假”的元素。