I want to copy the object of a variable to assign to another variable and only change some properties in the object of the new variable without changing the old object.
I create new object for new variable and change properties but when print out old variable is also changed. how to fix it?
let thongTinMuaXeKhachA = {
iDluotmua:`abc129867`,
nguoiSohuu:{
ten: `Pham Van A`,
tuoi: 35,
gioTinh: `nam`,
namSinh: 1984,
diaChi: `ha noi`,
cccd: 12345678,
},
thongTinXe: {
tenXe: `Vinfast luxA 2.0`,
hangXe: `Vinfast`,
soCho: 5,
tocDoTrungBinh: 90,
mauSac: `Den`,
giaBan: 1200000000,
namSanXuat: 2019,
},
ngayMua: `26/01/2022`,
};
console.log(`Thong tin khach hang A:`,thongTinMuaXeKhachA);
console.log(`--------------------------`);
let thongTinMuaXeKhachB = Object.assign({},thongTinMuaXeKhachA);
thongTinMuaXeKhachB.nguoiSohuu.ten = `Pham Van B`;
console.log(thongTinMuaXeKhachA);
console.log(thongTinMuaXeKhachB);