final Context context = RuntimeEnvironment.application;
答案 0 :(得分:0)
您需要遍历array2
,并使用array1
检查Array.find()
中是否存在对象。然后,您可以将找到的对象的isRecommended
更改为true
:
var array1 = [{
"_id": "5b7229fd5fd0b77763cd5d0b",
"title": "Nexus of knowledge",
"isRecommended": false,
}, {
"_id": "5b7229d15fd0b77763cd5adc",
"title": "Nexus of knowledge",
"isRecommended": false,
}, {
"_id": "5b7229c45fd0b77763cd5a11",
"title": "Nexus of knowledge",
"isRecommended": false,
}, {
"_id": "5b7229be5fd0b77763cd59b9",
"title": "Nexus of knowledge",
"isRecommended": false,
}, {
"_id": "5b7229be5fd0b77763cd59bf",
"title": "Nexus of knowledge",
"isRecommended": false,
}, {
"_id": "5b7229c15fd0b77763cd59fb",
"title": "Nexus of knowledge",
"isRecommended": false,
}];
var array2 = [{
"_id": "5b7229c15fd0b77763cd59fb"
}, {
"_id": "5b7229be5fd0b77763cd59bf"
}, {
"_id": "5b7229be5fd0b77763cd59b9"
}];
array2.forEach((item) => {
var array1Obj = array1.find(({_id}) => item._id === _id);
if(array1Obj) {
array1Obj.isRecommended = true;
}
});
console.log(array1);