Menu

gitpiper

filterUnique javascript Code Snippet in 2024

arraybeginner

Last Updated: 22 December 2024

Creates an array with the unique values filtered out.

  • Use new Set() and the spread operator (...) to create an array of the unique values in arr.
  • Use Array.prototype.filter() to create an array containing only the non-unique values.
const filterUnique = arr => [...new Set(arr)].filter(i => arr.indexOf(i) !== arr.lastIndexOf(i));
filterUnique([1, 2, 2, 3, 4, 4, 5]); // [2, 4]

javascript snippet similar to filterUnique For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️