function filterJson(data, Name) { //data是json对象,Name是根据什么字段去重
var map = {},
dest = [];
for (var i = 0; i < data.length; i++) {
var ai = data[i];
if (i == 0) {
dest.push(ai);
} else {
var filterData = dest.filter(function (e) {
return e[Name] == ai[Name];
})
if (filterData.length == 0) {
dest.push(ai);
}
}
}
return dest;
let arr1 = [1,2,3,5,8,9]
let arr2= [1,3,5,7]
let res1 = arr2.filter((x)=>{
return arr1.includes(x)
})
console.log(res1) //[1,3,5]
const data = arr.slice(0,3).map(item=>item.code).toString()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)