I create an object with multiple properties -
var objOpts = {
option1: \'Option1\',
option2: \'Option2\',
option2: \'Option3\'
};
I t
One aditionnal otpion would be to use Object.assign
to set the properties to either null
or undefined
depending on your use case. This does not delete the properties but clears them. So you would do either of these :
// Modify the object directly
Object.assign(objOpts, {option4: null, option5: null});
OR
// Create a copy of the object with the properties cleared
const newObject = Object.assign({}, objOpts, {option4: null, option5: null});
You could also use an array to list the properties to clear with Array.reduce()
to create the last param of Object.assign()
.