javascript - 谁能用传播运算符解释这里发生了什么
问题描述
下面的代码给了我想要的输出,但我需要了解更多。任何人都可以用传播运算符解释这里发生了什么,
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
参考:解构赋值
推荐阅读
- javascript - 让谷歌表格在多列中自动更新时间有点麻烦
- sql - 我可以使用文件 .asp 执行此操作吗?
- reactjs - 使用 -p 标志时出现 webpack 错误
- sql - 如何在Oracle中多次更新与另一个表连接的表?
- python - 如何找到正值最接近零的熊猫记录?
- xaml - 资源字典:System.InvalidCastException
- c# - 我想将一个特定列从我的 DataGrid 导出到 Excel
- mysql - MySQL NOT IN 查询给出错误结果
- reactjs - Material Icons 只是渲染文本,React Materialize
- python - Python3 - 如何按元素的频率对列表进行排序?