我有两个数组,我正在比较两个值,然后设置一个 json 对象:
var compare = ["hh", "pictures", "videos", "aboutMe", "contactMe", "cat", "location"];
var data = ["pictures", "videos", "aboutMe", "contactMe", "cat", "location"];
for (var j=0; j<compare.length; j++) {
if (compare[j] === data[j]) {
self.MenuItems.menu_item[j].added = "added";
}else if (compare[j] !== data[j]){
self.MenuItems.menu_item[j].added = "";
}
}
出于某种原因,对于 all self.MenuItems.menu_item[j]
,它们都等于 "add" 或 "";...