rename object key value javascript code example
Example 1: javascript rename keys in object
const array = [
{ id: "1", name: "Apple" },
{ id: "2", name: "Tomato" },
{ id: "3", name: "Orange" },
{ id: "4", name: "Coconut" },
{ id: "5", name: "Strawberry" },
{ id: "6", name: "Banana" }
];
const newArray = array.map(item => {
return { itemId: item.id, itemName: item.name };
});
Example 2: 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);