const array = [
{id: 1, phone: "13712345678"},
{id: 2, phone: "18612345670"},
{id: 3, phone: "13712345678"},
{id: 4, phone: "13712345678"},
{id: 5, phone: "18612345670"},
{id: 6, phone: "13777777777"},
];
const checkSame = array => {
let obj = {}
array.map((item)=>{
if(obj[item.phone]){
obj[item.phone].push(item);
} else {
obj[item.phone] = [item]
}
})
let result = [];
Object.keys(obj).map((key) => {
if(obj[key].length > 1){
result.push({
phone: key,
number: `重复数量${obj[key].length}`,
list: obj[key]
})
}
});
return result;
}
(() => {
const result = JSON.stringify(checkSame(array));
document.write(`发现重复的数据:<br />${result}`)
})();
console