In my file, I am exporting an object in the following manner:
export const LINECHART2_DATA = {
series: [{
data: [],
name: 'HR',
},
{
etc...
}]
}
The way I import it is like this:
import { LINECHART2_DATA } from '../chart-options/options';
I have a method that looks like this:
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 shown above, I am using the slice() method on the series array from LINECHART2_DATA and then adding some data to it. When a new bed is passed into the method with a null seriesContainer, it gets sliced once again, but this time it contains the data added by the previous bed. Since I am utilizing slice(), I expected to just obtain the value of LINECHART2_DATA, not the reference. What could be causing this issue?