Javascript JSON数组中相似值的删除
我想显示目前使用Angular 7的两个数组中不相似的数组值Javascript JSON数组中相似值的删除,javascript,Javascript,我想显示目前使用Angular 7的两个数组中不相似的数组值 json1 = { "status": "success", "data": { "priority": [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ] } } res = { "status": "success", "data": { "
json1 = {
"status": "success",
"data": {
"priority": [
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
]
}
}
res = {
"status": "success",
"data": {
"priority": ["1", "2"]
}
}
if (this.res.status == 'success') {
console.log(JSON.stringify(this.res))
this.prioritydata = [];
for (let i in this.res.data.priority) {
for (let j in this.json1.data.priority) {
if (this.res.data.priority[i] == this.json1.data.priority[j]) {
this.prioritydata.push(this.json1.data.priority[j]);
console.log("prioritydatasuccess - " + JSON.stringify(this.prioritydata))
}
}
}
}
exp answer - ["3", "4", "5", "6", "7", "8", "9", "10"]
你可以像那样使用
过滤器
let result = json1.data.priority.filter(value => json1.data.priority.indexOf(value) === -1);