Method 1: Renaming the object by simple assignment of variables. After the assignment of variable or variables we will delete the old key,value pair and print the new key value pair.
obj['New key'] = obj['old key'];
Note: Renaming the object by simple assignment of variable could be applied on multiple key, value pairs.
Output before rename:
Output after rename:
In this approach we will rename the given object key by utilizing defineProperty() to manipulate the property of the object.
This static method is used to define a new property of an object or modify an existing one, and returns the object. It accepts 3 parameters. They are: Object to be modified, name of the key, and the description attribute respectively in that order.
Object.defineProperty(obj, key, description)
Output before renaming:
Output after renaming:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.