I have an object that I use to have reset values which looks like this:
export const cleanTeam = {
id: "",
name: "",
players: []
}
Then I create a new object using cleanTeam
that looks like this:
let team1 = cleanTeam;
I will then set property values in team1
such as:
team1.id = 123;
team1.name = "My New Team";
Later, I create team2
using cleanTeam
so that I have a new object with the same structure but no values. However, I noticed that the values I assigned are in cleanTeam
as well. In other words, my cleanTeam
looks like this now:
{
id: 123,
name: "My New Team",
players: []
}
Shouldn't cleanTeam
stay intact as I set values in team1
?
I have an idea why this is happening. I think both cleanTeam
and team1
are pointing to the same object in memory. How do I keep cleanTeam
object clean?