change key of object javascript code example

Example 1: renemane object key js

obj = { name: 'Bobo' } //key: value
obj.newName = obj.name // on object create new key name. Assign old value to this
delete obj.name //delete object with old key name

Example 2: js rename property

function renameProperty(obj, oldName, newName) {
  obj[newName] = obj[oldName];
  delete obj[oldName];
}

Example 3: js change key value in object

var object = { boo:true, baa:5 };
console.log(object);
function change() {
  object.boo = false;
  object.baa++;
};
change();
console.log(object);
//Hope this helps!