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:
- How to rename columns in Pandas DataFrame
- Difference between Primary key and Super key
- HTML | DOM Object Object
- How to select first object in object in AngularJS?