I'm making a script where I create an object, and I want to make a copy of it, but when I assign the object to another variable if I change it will change both.
I've been reading a book and what I understand is that is is a reference and not a value, but I want to copy an object and treat them separately from that point. This is an example of what I do:
var myObject = {};
var copyOfMyObject = myObject;
myObject.foo = 'bar';
console.log(myObject, copyOfMyObject);
//logs Object {foo="bar"} Object {foo="bar"}
Is there a way to copy the whole object where I can change their properties independently without affecting the other?