Let's say I have an array of objects:
var people = [
{name: "Jack", height: 180},
{name: "Marry", height: 170},
{name: "Susan", height: 162},
]
If I take the first person and change the height like this:
var jack = people[0];
jack.height = 163;
Then this change is reflected in the object in the array as well like this:
people = [
{name: "Jack", height: 163},
{name: "Marry", height: 170},
{name: "Susan", height: 162},
]
However if I reassign the object like this
jack = {name: "Jack the developer", height: 163}
The array doesn't change:
people = [
{name: "Jack", height: 163},
{name: "Marry", height: 170},
{name: "Susan", height: 162},
]
How should I assign jack
so that it changes the reference?