var actual = { first: 1, second : 2 }
var copy = actual;
delete copy.first;
When I console log the copy, it doesnt have the first property on it, but when I console log actual, even that object doesnt have the first property.
Can someone please explain what is happening here? And how to avoid this?
Expected:
actual: { first: 1, second : 2 }
Copy: { second: 2 }
P.S: I know that that I can assign second property directly on the copy object without copying, this is just an example. I'm dealing with very large objects. So I have to copy and then delete the properties without affecting the actual object.
Thank you