Remove Array Duplicates in ES6

const array = ['🐑', 1,  2, '🐑','🐑', 3];

// 1: "Set"
[...new Set(array)];

// 2: "Filter"
array.filter((item, index) => array.indexOf(item) === index);

// 3: "Reduce"
array.reduce((unique, item) => 
  unique.includes(item) ? unique : [...unique, item], []);


// RESULT:
// ['🐑', 1, 2, 3];

https://www.samanthaming.com/tidbits/43-3-ways-to-remove-array-duplicates/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.