I have a file where I'm exporting an object like this:
export const LINECHART2_DATA = {
series: [{
data: [],
name: 'HR',
},
{
etc...
}]
}
I'm importing it like this:
import { LINECHART2_DATA } from '../chart-options/options';
I have the following method:
prepareLineChartDataContainer(bed: BedDetails) {
//Clear data to prepare for new bed
if (bed.seriesContainer == null) {
bed.seriesContainer = LINECHART2_DATA.series.slice();
} else {
bed.seriesContainer.forEach(series => {
series.data.length = 0;
});
}
//Add data to seriesContainer
this.vitalSigns.forEach(vs => {
bed.timeWindows.forEach(tw => {
bed.seriesContainer.find(series => series.name == vs).data.push(tw['avg' + vs]);
});
});
}
As you can see above, I'm slicing the series array from LINECHART2_DATA
, then pushing some data to it. When a new bed
is passed into the method with a null seriesContainer
, it will be sliced once again, but this time it will contain the data that was added by the previous bed
. Since I am using slice()
, I was expecting to just get the value of LINECHART2_DATA
, not the reference. What am I doing wrong?