I'm trying to copy an attribute to a new object and then delete the attribute from the original object. This is for a Redux Reducer I'm trying to flatten. This is not the same question as above. Cloning helps but both are still being deleted in the reducer.
i.e. parent{child} to {parent, child}
function mergeAndDelete(state, type, id, ent, attrib) {
const clone = { ...ent[attrib] };
merge(state, type, id, clone);
delete ent[attrib];
}
I thought the spread operator would make a new copy of the object?
Both the clone and the original are getting deleted in this method.