开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜