how to replace objects properties without changing other properties and if uneven number of objects are allocated, copy over other properties?
I guess the question might not make any sense. The example will explain everything. Lets say I have:
var oldData = {
fruits: fruits,
veggies: [{
sweet: false,
colour: red,
data: [1, 2, 3]
}]
};
var newData = {
veggies: [{
sweet: true,
data: [99, 100, 101]
},
{
sweet: false,
data: [888, 777, 665],
}]
};
var standardColor = "blue";
The goal is to:
- replace old veggies data with new data
- replace old veggies sweet value with new sweet value
- retain old veggies colour value, unless there is a new one in new data, therefore replace it.
- if a following new veggies object does not have colour, use standardColor - "blue"
- leave fruits untouched
Problems:
- newData veggies can have more objects than oldData, therefore I would need to iterate through them somehow?
My poor attempt:
function replaceVeggies (newData) {
oldData.veggies = newData.veggies
};