konradolejnik
konradolejnik

Reputation: 91

Spread syntax to remove

I wan't remove one key. Look this

console.log(state);

i getting {1: {here is next object}}, next

const { 1: deletedValue, ...newState } = state;
console.log(newState);
console.log(state);

i getting

{1: {here is next object}}
{1: {here is next object}}

Removal does not work. I do not understand why

In the comment you invited to describe how the data looked more accurate:

state: {1: {id: 1, content: {name: "xyz", surname: "dsd"}},
2: {id: 2, content: {name: "abc", surname: "dsq"}}
}

Upvotes: 3

Views: 110

Answers (1)

Nina Scholz
Nina Scholz

Reputation: 386730

It looks like a babeljs problem.

The problem with a number as property for a 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);

Take a stringed number as target property instead of just the number.

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);

Upvotes: 4

Related Questions