A

Unique values in a JavaScript array

public
andrei.k Oct 21, 2023 Never 23
Clone
JavaScript unique.js 8 lines (5 loc) | 218 Bytes
1
const array = ['a', 1, 'b', 2, '1', 'c', 'a'];
2
const unique = array.filter((value, index, arr) => arr.indexOf(value) === index);
3
4
console.log(unique);
5
6
const unique2 = [...new Set(array)];
7
8
console.log(unique2);