const obj = {
a: 1,
b:2,
c:3
}
const first = obj.a;
obj.z = first;
obj.a = '';
when I apply obj.a = ''; I get the result
const obj = {
a: '',
b:2,
c:3,
z:'',
}
it causes obj.z to change too but I need to keep the original value of z --> 1;
Unfortunately Js uses assign by reference in default so you need to using assign by value you can reach that by Object.assign(), Here's a link illustrate the mentioned method.
Try this:
const obj = {
a: 1,
b:2,
c:3
}
const first = obj.a;
Object.assign(obj, {z: first});
obj.a = '';