let arrObj = [
{ name: "bb", id: 10 },
{ name: "cc", id: 10 },
{ name: "vv", id: 22 },
{ name: "kk", id: 15 },
{ name: "tt", id: 55},
{ name: "uu", id: 15 }
];
// 数组对象去重(方法一)
for( let i = 0; i < arrObj.length; i++ ){
for( let j = i+1; j < arrObj.length; j++ ){
if( arrObj[i].id == arrObj[j].id ){
arrObj.splice(j,1)
j--
}
}
}
// 数组对象去重(方法二)
let obj = {}
arrObj = arrObj.reduce( (one,two) =>{
obj[two.id] ? "" : obj[two.id] = true && one.push(two)
return one
},[])
// 数组对象排序
arrObj = arrObj.sort( (one,two) =>{
return one.id - two.id
})
// console.log(222,arrObj)
//根据中文排序
let listdata = [
{bustype: '开业'},
{bustype: '备案'},
{bustype: '变更'},
{bustype: '注销'},
{bustype: '备案'},
{bustype: '注销'},
{bustype: '开业'},
]
listdata.sort((a, b) => {
let reg = /^[A-z]/;
if (reg.test(a.bustype) || reg.test(b.bustype)) {
if (a.name > b.bustype) {
return 1;
} else if (a.bustype < b.bustype) {
return -1;
} else {
return 0;
}
} else {
return a.bustype.localeCompare(b.bustype, "zh");
}
});