How to Rename an Object's Key in JavaScript

 

The correct and secure way of renaming an object key is the following 

const obj = {oldKey: 'value'};

obj['newKey'] = obj['oldKey'];
delete obj['oldKey'];

console.log(obj);

Tags:

Share:

Related posts