How to Remove Object Property Without Using Delete Operator ?
const obj = {
name : 'Roy',
country : 'India',
region : 'Delhi'
}
Object Destructuring
can be used to delete a property from the above JavaScript object.
Suppose you want to remove region
property. You can destrcuture the obj
object into two objects.
const {region, ...otherInfo} = obj;
// otherinfo - {name: 'Roy', country: 'India'}
Here otherInfo
is your object without region. Similarly, you can also delete multiple properties too.
const {region, name, ...otherInfo} = obj;
// otherinfo - {country: 'India'}
Note:: The original object obj
remains unchanged.