I am using React.
I have an array of objects in my state.
this.state = {
team: [{
name:'Bob',
number:23
},
{
name:'Jim',
number:43
}]
}
When I try to make a copy of the array to change a object's property, I don't get the results I want.
I have tried:
let tempTeam = [...this.state.team]
Any change to tempTeam also mutates this.state.team
AND
let tempTeam = this.state.team.map(player => return {...player})
This just throws an error, it doesn't like {...player}
How can I get the array of objects without it referencing this.state.team
?