Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"}}
}
like image 281
konradolejnik Avatar asked Jul 20 '26 17:07

konradolejnik


1 Answers

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);
like image 102
Nina Scholz Avatar answered Jul 23 '26 06:07

Nina Scholz