I create an object with multiple properties -
var objOpts = {
option1: \'Option1\',
option2: \'Option2\',
option2: \'Option3\'
};
I t
One way is to create a separate function which takes your object and properties as argument.
Js fiddle example
Code also below:
var objOpts = {
option1: 'Option1',
option2: 'Option2',
option3: 'Option3',
option4: 'Option4'
};
/**
* Method for removing object properties
*
*/
var removeObjectProperties = function(obj, props) {
for(var i = 0; i < props.length; i++) {
if(obj.hasOwnProperty(props[i])) {
delete obj[props[i]];
}
}
};
// remove
removeObjectProperties(objOpts, ["option1", "option2"]);
// objOpts - after
console.log(objOpts);