Script to rename a key of a JS object's property
Can someone explain why the following simple/basic script to rename the key of an object's property appears to work for the JS object displayed below
const obj = { firstName: 'Sling', lastName: 'Academy' };
obj.name = obj.firstName; // create a new property with the same value
delete obj.firstName; //delete the old property
but fails to work for a JS object of the type provided below:
const obj = {firstName:{address:'' '',city:'' '', state:'' '', zip:'' '', phone:'' ''},
secondName:{address:'' '',city:'' '', state:'' '', zip:'' '', phone:'' ''},
thirdName: {address:'' '',city:'' '', state:'' '', zip:'' '', phone:'' ''},
.
.
.
}}
All considered, I am curious to know what changes may be made to the script initially provided to rename a key or keys for the JS object shown above to rename firstName, secondName, thirdName, …..
Thank you ahead of time.
