Files
30-seconds-of-code/snippets/js/s/unique-elements-in-array.md
Angelos Chalaris 9d032ce05e Rename js snippets
2023-05-19 20:23:47 +03:00

448 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Unique values in array snippet javascript
array
shelf-plant 2020-10-22T20:24:44+03:00

Finds all unique values in an array.

  • Create a 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]