筛选出数组中具有指定值之一的元素

5年以前  |  阅读数:368 次  |  编程语言:JavaScript 

筛选出数组中具有指定值之一的元素。

使用Array.filter()创建不包括的数组 (使用!Array.includes()) 所有给定值。

const without = (arr, ...args) => arr.filter(v => !args.includes(v));
// without([2, 1, 2, 3], 1, 2) -> [3]

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8