let newArr =[{id:'1',content:''},{},{id:2},{id:2}]
封装了一个方法,调用即可
resetArray(nowArr){
let arr1 = []
let obj ={}
//去除空数组
for (let j in nowArr) {
for (let prop in nowArr[j]) {
if (prop != '' && nowArr[j][prop] != '') {
obj = nowArr[j]
}
}
if(Object.keys(obj)!=0){
arr1.push(obj)
}
}
(function () {//去除数组中重复对象
let unique = {};
arr1.forEach(function (a) {
unique[JSON.stringify(a)] = 1
});
arr1 = Object.keys(unique).map(function (u) {
return JSON.parse(u)
});
return arr1
})(arr1)
return arr1
},
网友评论