I am trying to remove a property from an object using the spread operator. Traditionally I have done this:
const original_object = { prop1 : 'string1', prop2: 'string2' };
const { prop1, ...rest } = original_object;
In the above situation, the removed property(prop1) will no longer exist within the rest object.
Suppose there is a more intricate property that I would like to remove, such as an object within the object.
const original_object = {
prop1: 'string1'
prop2: {
prop3: 'string3',
prop4: 'string4'
}
}
const { *remove prop3 of prop2 only here*, ...rest} = original_object;
console.log(prop3); // => 'string3';
What is the most elegant/easiest solution to do this? I want everything but the one prop3 of prop2 to be included in the object, in the exact same structure.