This question already has answers here:
Closed 3 years ago.
I am having a little problem assigning objects in javascript.
take a look at this sample code that reproduces my problem.
var fruit = {
name: "Apple"
};
var vegetable = fruit;
vegetable.name = "potatoe";
console.log(fruit);
it logs
Object {name: "potatoe"}
How can I assign the value not the reference of an object to another object?