定义
filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
注意:filter() 不会对空数组进行检测。filter()不会改变原始数组。
用法
过滤为 “假” 的值
Array.prototype.filter(Boolean)
等价于
Array.prototype.filter((item) => {return Boolean(item)})
可过滤去除0、undefined、null、NaN、''、false
filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
注意:filter() 不会对空数组进行检测。filter()不会改变原始数组。
Array.prototype.filter(Boolean)
等价于
Array.prototype.filter((item) => {return Boolean(item)})
可过滤去除0、undefined、null、NaN、''、false