JSFiddle - React, Tailwind, and code Playground

by Brandon Minton

JavaScript

Object.defineProperty(
    Object.prototype, 
    'renameProperty',
    {
        writable : false, // Cannot alter this property
        enumerable : false, // Will not show up in a for-in loop.
        configurable : false, // Cannot be deleted via the delete operator
        value : function (oldName, newName) {
            // Check for the old property name to 
            // avoid a ReferenceError in strict mode.
            if (this.hasOwnProperty(oldName)) {
                this[newName] = this[oldName];
                delete this[oldName];
            }
            return this;
        }
    }
);
var obj = {
    test1: 'blah1',
    test2: 'blah2',
    test3: 'this value gonna disappear'
}
obj.renameProperty('test2', 'test3')
console.log(JSON.stringify(obj))