Search This Blog

Javascript: remove duplicated values from array

Get distinct values from Array
let array = ['aaa', 'bbb', 'ccc', 'bbb', 'ddd'];
console.log(array);

array = Array.from(new Set(array));
console.log(array);



Get distinct values from Map
const map = new Map<string, number>();
map.set('foo', 1);
map.set('bar', 2);
map.set'zoo', 1);
const distinctValues = Array.from(new Set(map.values()));



see also

No comments:

Post a Comment