Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change property name

Tags:

javascript

I have a JavaScript object as follows:

var a = {   Prop1: 'test',   Prop2: 'test2'  } 

How would I change the property name of Prop1 to Prop3?

I tried the following code but it didn't work...

for (var p in r){   p.propertyName = 'Prop3'; } 
like image 755
firebird Avatar asked Dec 13 '11 01:12

firebird


People also ask

How do you change the name of a property?

Visit the land registry office: Once the name is legally changed the owner of the land should visit the land registry office and submit all the proofs related to the new name change with a nominal fee to get his or her name updated in the land records.

What is property name?

Property: Building/property name. Definition: The full name used to identify the physical building or property as part of its location.

What is it called to change the properties of an object?

Both physical and chemical property of an object may undergo a change. Explanation: Physical and chemical changes are the two different sorts of changes. Physical Change. A change that simply affects the physical condition of matter is called a physical change.


1 Answers

That isn't directly possible.

You can just write

a.Prop3 = a.Prop1; delete a.Prop1; 
like image 89
SLaks Avatar answered Oct 11 '22 12:10

SLaks