change object reference javascript code example
Example 1: set variable to object without editing old object js
// Deep Clone
obj = { a: 0 , b: { c: 0}};
let deepClone = JSON.parse(JSON.stringify(obj));
Example 2: set variable to object without editing old object js
var newObject = jQuery.extend(true, {}, myObj);
//requires jquery
Example 3: javascript clone object
var sheep={"height":20,"name":"Melvin"};
var clonedSheep=JSON.parse(JSON.stringify(sheep));
//note: cloning like this will not work with some complex objects such as: Date(), undefined, Infinity
// For complex objects try: lodash's cloneDeep() method or angularJS angular.copy() method