Files
30-seconds-of-code/javascript/snippets/without.md
2023-05-01 22:35:56 +03:00

475 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Filter out matching array elements snippet
array
dying-flowers 2020-10-22T20:24:44+03:00

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

  • Use Array.prototype.includes() to find values to exclude.
  • Use Array.prototype.filter() to create an array excluding them.
const without = (arr, ...args) => arr.filter(v => !args.includes(v));
without([2, 1, 2, 3], 1, 2); // [3]