js--过滤无效值_js--过滤无效值

学习资源推荐 学习资源推荐

代码

let arr=[undefined, null, "", 0, false, NaN, 1, 2].filter(Boolean);
console.log(arr) // [1,2]