任何人都可以用传播运算符解释这里发生了什么
Can anyone please explain what's happening here with spread operator
下面的代码给出了我想要的输出,但我需要了解更多。任何人都可以用传播运算符解释这里发生了什么,
const myObject = {
"employeeid": "160915848",
"firstName": "tet",
"lastName": "test",
"email": "test@email.com",
"country": "Brasil",
"currentIndustry": "aaaaaaaaaaaaa",
"otherIndustry": "aaaaaaaaaaaaa",
"currentOrganization": "test",
"salary": "1234567"
};
const {otherIndustry,currentOrganization, ...otherIndustry2} = myObject;
console.log(otherIndustry2);
Output:
{
"employeeid": "160915848",
"firstName": "tet",
"lastName": "test",
"email": "test@email.com",
"country": "Brasil",
"currentIndustry": "aaaaaaaaaaaaa",
"salary": "1234567"
};
这更像是一个对象解构赋值问题。
所以这一行const {otherIndustry,currentOrganization, ...otherIndustry2} = myObject;
是一个对象解构语句,它首先将otherIndustry
和currentOrganization
的值赋给同名变量,其余的值, 它们都作为对象分配给 otherIndustry2
下面的代码给出了我想要的输出,但我需要了解更多。任何人都可以用传播运算符解释这里发生了什么,
const myObject = {
"employeeid": "160915848",
"firstName": "tet",
"lastName": "test",
"email": "test@email.com",
"country": "Brasil",
"currentIndustry": "aaaaaaaaaaaaa",
"otherIndustry": "aaaaaaaaaaaaa",
"currentOrganization": "test",
"salary": "1234567"
};
const {otherIndustry,currentOrganization, ...otherIndustry2} = myObject;
console.log(otherIndustry2);
Output:
{
"employeeid": "160915848",
"firstName": "tet",
"lastName": "test",
"email": "test@email.com",
"country": "Brasil",
"currentIndustry": "aaaaaaaaaaaaa",
"salary": "1234567"
};
这更像是一个对象解构赋值问题。
所以这一行const {otherIndustry,currentOrganization, ...otherIndustry2} = myObject;
是一个对象解构语句,它首先将otherIndustry
和currentOrganization
的值赋给同名变量,其余的值, 它们都作为对象分配给 otherIndustry2