30秒学会 JavaScript 片段 · 2018年8月7日

30秒学会 JavaScript 片段 – without

Filters out the elements of an array, that have one of the specified values.

Use Array.prototype.filter() to create an array excluding(using !Array.includes()) all given values.

代码片段

const without = (arr, ...args) => arr.filter(v => !args.includes(v));

使用样例

without([2, 1, 2, 3], 1, 2); // [3]