Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  193] [ 3]  / answers: 1 / hits: 16831  / 8 Years ago, thu, june 30, 2016, 12:00:00
var b = {};
var a = b;
b.test = 123;
console.log(a.test);


I am trying to write code similar to the above, however for sake of not having to describe context I'll display that instead ^



After the line a = b I want to lose the reference from a to b, so I can update b without it affecting a, and vice-versa



Is this possible?


More From » javascript

 Answers
23

You can clone your object with Object.assign():



var a = Object.assign({}, b);

[#61568] Tuesday, June 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
christianu

Total Points: 481
Total Questions: 124
Total Answers: 99

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
1 Year ago
;