javascript get unique values from key code example

Example 1: javascript find unique values in array

// usage example:
var myArray = ['a', 1, 'a', 2, '1'];
var unique = myArray.filter((v, i, a) => a.indexOf(v) === i); 

// unique is ['a', 1, 2, '1']

Example 2: array unique values javascript

const myArray = ['a', 1, 'a', 2, '1'];
const unique = [...new Set(myArray)]; // ['a', 1, 2, '1']

Example 3: javascript get unique values from key

const unique = [...new Set(array.map(item => item.age))];

Tags:

Php Example