630 B
630 B
title, tags, expertise, author, cover, firstSeen, lastUpdated
| title | tags | expertise | author | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|---|
| Filter unique array values | array | beginner | maciv | blog_images/tulips-and-reeds.jpg | 2020-11-02T19:41:00+02:00 | 2020-11-02T19:41:00+02:00 |
Creates an array with the unique values filtered out.
- Use the
Setconstructor and the spread operator (...) to create an array of the unique values inarr. - 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]