1obj = { name: 'Bobo' } //key: value
2obj.newName = obj.name // on object create new key name. Assign old value to this
3delete obj.name //delete object with old key name
1const array = [
2 { id: "1", name: "Apple" },
3 { id: "2", name: "Tomato" },
4 { id: "3", name: "Orange" },
5 { id: "4", name: "Coconut" },
6 { id: "5", name: "Strawberry" },
7 { id: "6", name: "Banana" }
8];
9
10const newArray = array.map(item => {
11 return { itemId: item.id, itemName: item.name };
12});
13
14// Result:
15// [
16// { itemId: "1", itemName: "Apple" },
17// { itemId: "2", itemName: "Tomato" },
18// { itemId: "3", itemName: "Orange" },
19// { itemId: "4", itemName: "Coconut" },
20// { itemId: "5", itemName: "Strawberry" },
21// { itemId: "6", itemName: "Banana" }
22// ];
23