I want to update properties of objects from another object which will have corresponding property identifiers. Hopefully I will be able to use a loop to do so but due to my inexperience I cannot think how to do this.
I cannot just say
object1 = object2;
because the arrays in the object are being concatenated.
What I currently have looks like this:
if (direction === 'forw')
{
renderedCharts.electric.real.full = renderedCharts.electric.real.full.concat(newChartData.electric.real);
renderedCharts.electric.budget.full = renderedCharts.electric.budget.full.concat(newChartData.electric.budget);
renderedCharts.gas.real.full = renderedCharts.gas.real.full.concat(newChartData.gas.real);
renderedCharts.gas.budget.full = renderedCharts.gas.budget.full.concat(newChartData.gas.budget);
}
else if (direction === 'back')
{
for (var index in newChartData) // get the length of the arrays returned (all arrays will have the same number of elements
{
dataOffset += newChartData[index].real.length;
break;
}
renderedCharts.electric.real.full = newChartData.electric.real.concat(renderedCharts.electric.real.full);
renderedCharts.electric.budget.full = newChartData.electric.budget.concat(renderedCharts.electric.budget.full);
renderedCharts.gas.real.full = newChartData.gas.real.concat(renderedCharts.gas.real.full);
renderedCharts.gas.budget.full = newChartData.gas.budget.concat(renderedCharts.gas.budget.full);
}
but electric
or gas
need to be represented by any identifier but the identifiers in the objects will always be the same.