Skip to content Skip to sidebar Skip to footer

Renaming A Field In An Object

If I have the following object: JsonObj = { 'frames': { 'cinema': { 'sourceSize': { 'w': 256, 'h': 200 }, 'frame': { 'x': 0, 'y': 0, 'w': 256, '

Solution 1:

Set the somethingElse as a reference to what frames points to, then delete frames.

parsedJSON.somethingElse = parsedJSON.frames;
delete parsedJSON.frames;

The important thing here is that frames is simply a pointer to an object; if you delete the frames pointer, somethingElse still references a valid object.


Post a Comment for "Renaming A Field In An Object"