Files
30-seconds-of-code/snippets/uniqueElements.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

449 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Unique values in array array architectural 2018-01-17T19:02:49+02:00 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]