Created
March 10, 2016 16:52
-
-
Save sscovil/eca1176bc5113a8a2bc3 to your computer and use it in GitHub Desktop.
A JavaScript function for renaming an object property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renameProperty(object, oldKey, newKey) { | |
if (object instanceof Object && object.hasOwnProperty(oldKey) && oldKey !== newKey) { | |
Object.defineProperty(object, newKey, | |
Object.getOwnPropertyDescriptor(object, oldKey)); | |
delete object[oldKey]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment