I am performing the destructuring of an object, to make a new object that will have most of the values.
example:
const test = {
a:'a',
b:'b',
c:'c',
array:[
{ar1:'1',ar2:'2'},
{ar1:'2',ar2:'3'}
]
};
const {array,a, ...rest} = test;
const newObjet = {newData:array[0], rest};
console.log(newObjet);
As in the new object ( newObjet
) I am not interested in what it has a
and array
it was done that way, so far so good.
The problem is that I don't want a key to be created rest
on the new object. The result I want is similar to the following:
{
newData: {
"ar1": "1",
"ar2": "2"
},
b: "b",
c: "c"
}
Just do:
This way you also unstructure the rest object and it does not remain as a new property