【发布时间】:2022-01-13 12:18:22
【问题描述】:
我有两个对象 obj1 和 obj2。
当我合并时:
const obj1 = {
error_to_retrieve: "teste",
error_to_search_customer: "",
error_to_sync_timezone: "",
error_to_update_avatar: "",
error_to_update_profile: "",
error_to_validate_customer_token: "",
expired_session: "",
invalid_token: "",
invalid_token_text: ""
}
const obj2 = {
error_to_retrieve: "test",
error_to_search_customer: "test",
error_to_sync_timezone: "test",
error_to_update_avatar: "test",
error_to_validate_customer_token: "test",
expired_session: "test",
invalid_token: "test",
invalid_token_text: "test"
}
const obj3 = {...obj1, ...obj2};
console.log(obj3);
我得到了完整的 obj2,但它没有 key error_to_update_profile。
我如何维护第二个对象没有的第一个对象的密钥?
【问题讨论】:
-
error_to_update_profile.它对我有用。 ps,你的 obj1 和 obj2 上缺少逗号 -
我在浏览器的控制台中运行它,我有
error_to_update_profil键
标签: javascript object spread