为什么通过重命名对象的键会失去价值?
Why do I lose value by renaming the key of an object?
通过重命名对象的键,我丢失了值。如何确保只有键被更改而值保持不变?
这是我的对象
const items = {
"brand": "losee",
"target": "brand",
"item": {
"name": null,
"fabric": null,
"country": "CH",
"fit": "regular"
}
}
// for renaming the key I use this method
delete Object.assign(items, { prototype: items.item.fit }).fit;
console.log(items)
在这个方法之后我的对象看起来像这样
{
"brand": "losee",
"target": "brand",
"item": {
"name": null,
"fabric": null,
"country": "CH",
"prototype": null
}
}
我做错了什么?
谢谢大家
尝试分配给 items.item
const items = {
"brand": "losee",
"target": "brand",
"item": {
"name": null,
"fabric": null,
"country": "CH",
"fit": "regular"
}
}
delete Object.assign(items.item, { prototype: items.item.fit }).fit
console.log(items)
通过重命名对象的键,我丢失了值。如何确保只有键被更改而值保持不变?
这是我的对象
const items = {
"brand": "losee",
"target": "brand",
"item": {
"name": null,
"fabric": null,
"country": "CH",
"fit": "regular"
}
}
// for renaming the key I use this method
delete Object.assign(items, { prototype: items.item.fit }).fit;
console.log(items)
在这个方法之后我的对象看起来像这样
{
"brand": "losee",
"target": "brand",
"item": {
"name": null,
"fabric": null,
"country": "CH",
"prototype": null
}
}
我做错了什么? 谢谢大家
尝试分配给 items.item
const items = {
"brand": "losee",
"target": "brand",
"item": {
"name": null,
"fabric": null,
"country": "CH",
"fit": "regular"
}
}
delete Object.assign(items.item, { prototype: items.item.fit }).fit
console.log(items)