I have an array of objects and each object has these values
id: "53ed5e27-23a5-4a06-b53f-d0113d607fb5"
measure:
units: Array(2)
0: {perPortion: 15, name: "tbsp"}
1: {perPortion: 1, name: "ml"}
I am looping over the array and passing an on click function to a button.
function handleClick(index: number, ingredient: Data) {
//copy original array
const newListArr = [...props.data];
newListArr[index] = {
...newListArr[index],
}
}
The function is getting the index of the object clicked. I am copying the looped array and then I am trying to use the spread operator to bring in all the properties.
My problem is that I dont know how to use spread operator with nested objects.
I want to get only target the value of the "perPortion" key inside the units array without affecting anything else. How can i do that ?
Thank you in advance for the help!