Object.assign
doesn't deep copy an object. considering following code it should print 0 0 0 1
but it is printing 0 0 1 1
.
var obj = {
"value": {
"default": 0
}
};
var newo = Object.assign({}, obj);
console.log(obj.value.default);
console.log(newo.value.default);
newo.value.default = 1;
console.log(obj.value.default);
console.log(newo.value.default);
I know we can use JSON.parse(JSON.stringify(obj))
. but is that a best practice solution?