1const myArray = ['a', 1, 'a', 2, '1'];
2const unique = [...new Set(myArray)]; // ['a', 1, 2, '1']
1//ES6
2let array = [
3 { "name": "Joe", "age": 17 },
4 { "name": "Bob", "age": 17 },
5 { "name": "Carl", "age": 35 }
6];
7array.map(item => item.age)
8 .filter((value, index, self) => self.indexOf(value) === index)
9
10> [17, 35]
1const myArray = [1,2,3,1,5,8,1,2,9,4];
2const unique = [...new Set(myArray)]; // [1, 2, 3, 5, 8, 9, 4]
3
4const myString = ["a","b","c","a","d","b"];
5const uniqueString = [...new Set(myString)]; //["a", "b", "c", "d"]
1var flags = [], output = [], l = array.length, i;
2for( i=0; i<l; i++) {
3 if( flags[array[i].age]) continue;
4 flags[array[i].age] = true;
5 output.push(array[i].age);
6}
7