I create an object with multiple properties -
var objOpts = {
option1: 'Option1',
option2: 'Option2',
option2: 'Option3'
};
I then add some more properties later on -
objOpts.option4 = 'Option4'
objOpts.option5 = 'Option5'
I'm then done with the two latter created properties ('Option4' & 'Option5') and I want to clear/delete both.
Currently I'd do it like so -
delete objOpts.option4
delete objOpts.option5
Is there another way to go about doing this? Imagine I'd added 5 more properties and needed to clear/delete them all that'd be five lines of almost identical 'delete' code
var extraOpts = ['option4','option5','option6','option7','option8']; for(index in extraOpts){ delete objOpts[extraOpts[index]]; }var extraOpts = {}; extraOpts.options = ['option4','option5','option6','option7','option8']; delete extraOpts.options; console.log(extraOpts.options);