>我有那个对象和简单的对象
public positions = {
reading: {
left: "0px",
},
writing: {
left: "0px",
},
speaking: {
left: "0px",
},
listening: {
left: "0px",
},
};
我需要检查某些"left"属性是否相同,以及它们是否将"top"属性添加到其中一个属性。例如,如果我有这样的对象:
public positions = {
reading: {
left: "10px",
},
writing: {
left: "20px",
},
speaking: {
left: "20px",
},
listening: {
left: "7px",
},
};
修鲁德改成这样:
public positions = {
reading: {
left: "10px",
},
writing: {
left: "20px",
},
speaking: {
left: "20px",
top: "10px"
},
listening: {
left: "7px",
},
};
我需要最简单的方法来做到这一点。
也许是这个?
const positions = {
reading: {
left: "0px",
},
writing: {
left: "0px",
},
speaking: {
left: "0px",
},
listening: {
left: "0px",
},
};
const positions2 = {
reading: {
left: "0px",
},
writing: {
left: "0px",
},
speaking: {
left: "0px",
},
listening: {
left: "0px",
},
};
for (var key in positions) {
if (positions2[key].left == positions[key].left) {
positions2[key].top = '10px'
}
}
console.log(positions2)