I have one array with the current week like:
[
{time: "Monday", value: 0},
{time: "Tuesday", value: 0},
{time: "Wednesday", value: 0},
{time: "Thursday", value: 0},
{time: "Friday", value: 0},
{time: "Saturday", value: 0},
{time: "Sunday", value: 0}
]
and another array with the current values from this week, e.g. for wednesday:
[
{time: "Monday", value: 5},
{time: "Tuesday", value: 10},
]
My Problem now is that I don’t know how to replace the two objects from the second array into the first array so that I have a result like this:
[
{time: "Monday", value: 5},
{time: "Tuesday", value: 10},
{time: "Wednesday", value: 0},
{time: "Thursday", value: 0},
{time: "Friday", value: 0},
{time: "Saturday", value: 0},
{time: "Sunday", value: 0}
]
2
Answers
I found a working solution for me:
You can achieve this by looping thru
defaultValues
and for each element it checks if there is a corresponding value in thecurrentValues
array, if found then it replaces the value, otherwise it keeps the original value