firebird firebird - 4 years ago 197
Javascript Question

change property name

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

for (var p in r) p.propertyName = 'Prop3';


but that did not work.

Answer Source

That isn't directly possible.

You can just write

a.Prop3 = a.Prop1;
delete a.Prop1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download