I want to do change the name of a key in an Object
. But when I want to do this with an if condition, I get this (Assignment to function parameter 'key')
error. How can i manipulate a key name ?
My Code:
const personData = [];
Object.keys(testItem).forEach((key) => {
item = testItem[key];
if (key === 'Name'){
key = 'Person Name';
}
personData.push({ name: key, data: Object.values(item) })
});
testItem data:
testItem = {Name: {...}, Surname: {...}}
I want the Name
key to change to Person Name
without error.