removing one property of an object
I have an object that looks like this.
{
par1: 'par1value',
par2: 'par2value',
par3: 'par3value'
};
I want to remove the property called par1
and save it separately so it looks like this
var par1 = 'par1value';
{
par2: 'par2value',
par3: 'par3value'开发者_JAVA技巧
};
Can someone suggest a nice way to do this
Get the property:
var value = obj.par1;
Remove the value from the object:
delete obj.par1;
More detail about delete can be found here.
It has been answered already here: How do I remove a property from a JavaScript object?
basically,
var parobject = {
par1: 'par1value',
par2: 'par2value',
par3: 'par3value'
};
var par1 = object.par1;
delete parobject.par1;
Addition: The delete operator is described in here: https://developer.mozilla.org/en/JavaScript/Reference/operators/special_operators/delete_operator
精彩评论