我有这个:const id = speakerRec.id;const firstName = speakerRec.firstName;const lastName = speakerRec.lastName;而且我认为有这样的事情,但记不起来了。const [id, firstName, lastName] = speakerRec;
2 回答

森栏
TA贡献1810条经验 获得超5个赞
您需要{}用于解构对象属性:
const {id, firstName, lastName} = speakerRec;
[] 用于数组解构:
const [one, two, three] = [1, 2, 3];
示范:
const speakerRec = {
id: "mySpeaker",
firstName: "Jack",
lastName: "Bashford"
};
const { id, firstName, lastName } = speakerRec;
console.log(id);
console.log(firstName);
console.log(lastName);
const [one, two, three] = [1, 2, 3];
console.log(one);
console.log(two);
console.log(three);
添加回答
举报
0/150
提交
取消