I am looking to update the keys' values of the 1st object within an array of objects.
Here is what I have attempted so far:
The array of objects:
const objArray: FoodItems[] = [
{
apple: 4,
banana: 7,
'mango & grapes': 9,
Cherry: 7,
},
]
The type of the above object is FooItems[]
:
export type FoodItems = {
apple: number;
banana: number;
'mango & grapes': number;
Cherry: number;
}
The new value that needs to be assigned to the key:
const newValue = 34;
The code snippet I used to attempt modifying each key:
objArray.map(item => ({
...item,
...{
apple: newValue,
banana: newValue,
'mango & grapes': newValue,
Cherry: newValue,
},
})),
Is there a more efficient way to achieve this task, rather than updating each key individually?
Thanks in advance...