get unique elements in an array javascript code example
Example 1: javascript array unique values
var arr = [55, 44, 65,1,2,3,3,34,5];
var unique = [...new Set(arr)]
Example 2: array unique values javascript
const myArray = ['a', 1, 'a', 2, '1'];
const unique = [...new Set(myArray)];
Example 3: how to find unique elements in array in javascript
let a = ["1", "1", "2", "3", "3", "1"];
let unique = a.filter((item, i, ar) => ar.indexOf(item) === i);
console.log(unique);
Example 4: unique values in array javascript
let uniqueItems = [...new Set(items)]
Example 5: javascript get unique values from array
const myArray = [1,2,3,1,5,8,1,2,9,4];
const unique = [...new Set(myArray)];
const myString = ["a","b","c","a","d","b"];
const uniqueString = [...new Set(myString)];