Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 358 Bytes

uniqueElements.md

File metadata and controls

16 lines (12 loc) · 358 Bytes
title tags
uniqueElements
array,beginner

Returns all unique values in an array.

  • Create a Set from the given array to discard duplicated values, then 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]