Files
30-seconds-of-code/snippets/uniqueElements.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

435 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
uniqueElements array,beginner 2018-01-17T19:02:49+02:00 2020-10-22T20:24:44+03:00

Finds all unique values in an array.

  • Create a new Set() from the given array to discard duplicated values.
  • Use the spread operator (...) to convert it back to an array.
const uniqueElements = arr => [...new Set(arr)];
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]