1const array =
2 [
3 { "name": "Joe", "age": 17 },
4 { "name": "Bob", "age": 17 },
5 { "name": "Carl", "age": 35 }
6 ]
7
8const key = 'age';
9
10const arrayUniqueByKey = [...new Map(array.map(item =>
11 [item[key], item])).values()];
12
13console.log(arrayUniqueByKey);
14
15 /*OUTPUT
16 [
17 { "name": "Bob", "age": 17 },
18 { "name": "Carl", "age": 35 }
19 ]
20 */
21
22 // Note: this will pick the last duplicated item in the list.