I have the following object:
const info = [{ name: 'John', address: 'america', gender: 'Male', job: 'SE' }];
And I need to spread this array object and get this as
form:{
name:"John",
address:"america",
gender:"Male",
job:"SE"
}
How can I do that?
You don't need spread for that unless you want to make a shallow copy of the object. Instead, just use the object that's in the array:
or as a property on an object:
At that point,
form
/obj.form
andinfo[0]
are both pointing to the same object.If you do want to make a shallow copy, then spread is useful:
or
There,
form
/obj.form
points to a new object that has a copy ofinfo[0]
's properties.