1const addresses = [...]; // Some array I got from async call
2
3const uniqueAddresses = Array.from(new Set(addresses.map(a => a.id)))
4 .map(id => {
5 return addresses.find(a => a.id === id)
6 })
1let person = [
2{name: "john"},
3{name: "jane"},
4{name: "imelda"},
5{name: "john"},
6{name: "jane"}
7];
8
9const data = Array.from(new Set(person.map(JSON.stringify))).map(JSON.parse);
10console.log(data);
1let person = [
2{name: "john"},
3{name: "jane"},
4{name: "imelda"},
5{name: "john"},
6{name: "jane"}
7];
8
9const obj = [...new Map(person.map(item => [JSON.stringify(item), item])).values()];
10console.log(obj);
1let days = ["senin","senin","selasa","selasa","rabu","kamis", "rabu"];
2let fullname = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"},{name: "jane"}];
3
4// REMOVE DUPLICATE FOR ARRAY LITERAL
5const arrOne = new Set(days);
6console.log(arrOne);
7
8const arrTwo = days.filter((item, index) => days.indexOf(item) == index);
9console.log(arrTwo);
10
11
12// REMOVE DUPLICATE FOR ARRAY OBJECT
13const arrObjOne = [...new Map(person.map(item => [JSON.stringify(item), item])).values()];
14console.log(arrObjOne);
15
16const arrObjTwo = Array.from(new Set(person.map(JSON.stringify))).map(JSON.parse);
17console.log(arrObjTwo);
1const uniqify = (array, key) => array.reduce((prev, curr) => prev.find(a => a[key] === curr[key]) ? prev : prev.push(curr) && prev, []);
2
1let uniqIds = {}, source = [{id:'a'},{id:'b'},{id:'c'},{id:'b'},{id:'a'},{id:'d'}];
2let filtered = source.filter(obj => !uniqIds[obj.id] && (uniqIds[obj.id] = true));
3console.log(filtered);
4// EXPECTED: [{id:'a'},{id:'b'},{id:'c'},{id:'d'}];