📌  相关文章
📜  从数组 javascript 代码示例中删除重复对象

📅  最后修改于: 2022-03-11 15:02:27.645000             🧑  作者: Mango

代码示例6
let days = ["senin","senin","selasa","selasa","rabu","kamis", "rabu"];
let fullname = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"},{name: "jane"}];

// REMOVE DUPLICATE FOR ARRAY LITERAL
const arrOne = new Set(days);
console.log(arrOne);

const arrTwo = days.filter((item, index) => days.indexOf(item) == index);
console.log(arrTwo);


// REMOVE DUPLICATE FOR ARRAY OBJECT
const arrObjOne = [...new Map(person.map(item => [JSON.stringify(item), item])).values()];
console.log(arrObjOne);

const arrObjTwo = Array.from(new Set(person.map(JSON.stringify))).map(JSON.parse);
console.log(arrObjTwo);