10

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'
};

Can someone suggest a nice way to do this

jarn
  • 263
  • 1
  • 2
  • 7
  • 4
    possible duplicate of [How to remove a property from a javascript object](http://stackoverflow.com/questions/208105/how-to-remove-a-property-from-a-javascript-object) – Andrea Nov 13 '13 at 17:56

2 Answers2

19

Get the property:

var value = obj.par1;

Remove the value from the object:

delete obj.par1;

More detail about delete can be found here.

Community
  • 1
  • 1
Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
4

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

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108