tags:

views:

24

answers:

1

If I have the following:

var myObj = { "Foo":{"prop1":"abc", "prop2":123 }, "Bar":{"prop1":"def", "prop2":456 } };

Is there a quick and safe way to modify the object such that it becomes:

{ "Foo":{"prop1":"abc", "prop2":123 }, "Bar":{"PROP1":"def", "PROP2":456 } }

I'd like to change the casing of the property names of the Bar property on-the-fly. Is this possible?

+3  A: 

Yes, it is. try this code

   var myObjBar = myObj['Bar'];
    for (p in myObjBar) {
      if (myObjBar.hasOwnProperty(p)) {
        var v = myObjBar[p],
            k = p.toUpperCase();
        delete myObjBar[p];
        myObjBar[k] = v;

      }
    }
Fabrizio Calderan