我想把Jacob的keyvalue内容和Guillermo的keyvalue内容互换。
我可以把Guillermo换成Jacob,但不能换成其他方式。
这是我的代码,只对了一半,我想把Jacob的keyvalue内容和Guillermo的keyvalue内容互换。
let students = {
jacob: {
classes: ["math", "chemistry", "english"],
grade: 11,
age: 16,
},
guillermo: {
classes: ["history", "math", "physics"],
grade: 12,
age: 17,
},
};
let temp = students.jacob;
students.guillermo = temp;
let temp1 = students.guillermo;
students.jacob = temp1;
console.log(students)
你需要复制之前,重新分配
let students = {
jacob: {
classes: ["math", "chemistry", "english"],
grade: 11,
age: 16,
},
guillermo: {
classes: ["history", "math", "physics"],
grade: 12,
age: 17,
},
};
let temp = students.jacob;
let temp1 = students.guillermo;
students.guillermo = temp;
students.jacob = temp1;
console.log(students)