JavaScript: Find all unique values in an array
JavaScript Array: Exercise-45 with Solution
Unique Values in Array
Write a JavaScript program to find all the unique values in a set of numbers.
- Create a new Set() from the given array to discard duplicated values.
- Use the spread operator (...) to convert it back to an array
Sample Solution:
JavaScript Code :
Output:
[1,2,3,4,5] [1,2,3,4,5] [1,-2,3,4,-5,-6]
Flowchart :

Live Demo :
For more Practice: Solve these Related Problems:
- Write a JavaScript function that finds all unique values in an array by filtering out duplicates.
- Write a JavaScript function that uses a Set to return a new array of unique values from the input array.
- Write a JavaScript function that iterates through an array and collects unique elements manually.
- Write a JavaScript function that handles arrays with objects by converting them into comparable primitives and returning unique entries.
Improve this sample solution and post your code through Disqus.
Previous: Creates an object from an array, using the specified key and excluding it from each value.
.
Next: Permutations of an array elements
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.