我不会删除一把钥匙。看这个
console.log(state);
我得到{1: {here is next object}}
,
下一个
const { 1: deletedValue, ...newState } = state;
console.log(newState);
console.log(state);
我得到
{1: {here is next object}}
{1: {here is next object}}
删除不起作用。我不明白为什么
您在评论中邀请您描述数据看起来如何更准确:
state: {1: {id: 1, content: {name: "xyz", surname: "dsd"}},
2: {id: 2, content: {name: "abc", surname: "dsq"}}
}
答案 0 :(得分:4)
将数字作为destructuring assignment的属性的问题。
var object = { 1: 40, foo: 41, bar: 42, baz: 43 },
{ 1: y, foo: z, ...x } = object;
//^
console.log(x);
console.log(y);
console.log(z);
将字符串数字而不是数字作为目标属性。
var object = { 1: 40, foo: 41, bar: 42, baz: 43 },
{ '1': y, foo: z, ...x } = object;
//^^^
console.log(x);
console.log(y);
console.log(z);