Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Can someone suggest a nice way to do this

like image 334
jarn Avatar asked Apr 08 '11 23:04

jarn


2 Answers

Get the property:

var value = obj.par1;

Remove the value from the object:

delete obj.par1;

More detail about delete can be found here.

like image 200
Jason McCreary Avatar answered Oct 12 '22 20:10

Jason McCreary


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

like image 28
Aleadam Avatar answered Oct 12 '22 21:10

Aleadam