The original object is being affected when changes are made to the cloned object.
const original = {
"appList": [{
"appId": "app-1",
"serviceList": [{
"service": "service-1",
"mList": ["somedata"]
},{
"service": "service-2",
"mList": []
},{
"service": "service-3",
"mList": []
}]
}]
}
const clone = Object.assign({}, original);
Attempting to make the following change:
clone.appList = clone.appList.filter(app => app.appId == 'app-1').map( app => {
let serviceList = [...app.serviceList];
if(app.serviceList && app.serviceList.length) {
app.serviceList = serviceList.filter(service => {
const { mList } = service;
return mList && mList.length;
});
}
return app;
});
Notice that even the original object gets updated:
console.log(clone);
console.log(original);