js 筛选删除数组中符合条件的所有元素

filter用于对数组进行过滤。
它创建一个新数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。

注意:filter()不会对空数组进行检测、不会改变原始数组

let nums = [1, 2, 3, 4, 3, 5, 6];
let res = nums.filter(item=> item !== 3);
console.log(res); //  [1, 2, 4, 5, 6]

猜你喜欢

转载自blog.csdn.net/qq_41954585/article/details/130634332
今日推荐