I want to change the values of keys of the 1st object in an object array.
Following is the attempt I followed so far.
The object array:
const objArray: FoodItems[] = [
{
apple: 4,
banana: 7,
'mango & grapes': 9,
Cherry: 7,
},
]
The above object is of the type of FooItems[]
:
export type FoodItems = {
apple: number;
banana: number;
'mango & grapes': number;
Cherry: number;
}
The new value of key I need to assign:
const newValue = 34;
The code I tried to modify each key:
objArray.map(item => ({
...item,
...{
apple: newValue,
banana: newValue,
'mango & grapes': newValue,
Cherry: newValue,
},
})),
Please, may I know a simpler way of doing this, instead of changing each key individually?
Thanks in advance...