Javascript 谁能解释一下';这里发生了什么事
下面的代码提供了我想要的输出,但我需要了解更多。有人能解释一下spread operator的情况吗Javascript 谁能解释一下';这里发生了什么事,javascript,spread-syntax,Javascript,Spread Syntax,下面的代码提供了我想要的输出,但我需要了解更多。有人能解释一下spread operator的情况吗 const myObject = { "employeeid": "160915848", "firstName": "tet", "lastName": "test", "email": "tes
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
参考资料:我觉得这不像R代码,那么你为什么要使用
[spread]
标签呢?(提示:阅读标记wiki!)假设json数据从db返回。在这里,我想删除两列,或者我不想要属性(otherIndustry,currentOrganization)。因此,您没有接受提示。我已经为您修复了标签,并添加了一个[javascript]
,以便能够回答的人更有可能注意到这个问题。注意:如果你想知道答案,正确的标签很重要。(如果你不想要答案……你不应该问。)是的,这很有帮助。非常感谢用户4642212非常感谢您简单明了的回答。