Currently, I am working on implementing a filter functionality for a data array used in a LineChart within my Angular application using TypeScript. The structure of the data array is as follows:
var multi = [
{
"name": "test1",
"series": [
{
"date": new Date("2018-01-01T01:10:00Z"),
"value": 44
},...
]
},
{
"name": "test2",
"series": [
{
"date": new Date("2018-01-01T01:10:00Z"),
"value": 38
},...
]
},
{
"name": "test3",
"series": [
{
"date": new Date("2018-01-01T01:10:00Z"),
"value": 33
},...
]
}
];
My objective is to filter the items in the array based on the condition that the date falls between a 'fromDate' and a 'toDate'. I attempted the following approach:
obj.forEach(data => {
console.log(data.name);
data.series = data.series.filter((item: any) => {
item.date.getTime() >= fromDate.getTime() &&
item.date.getTime() <= toDate.getTime();
});
});
After executing this code snippet, the obj[]
array ends up with empty obj[i].series
arrays. Could anyone provide some assistance with resolving this issue? The iteration process seems correct as all dates are being logged during debugging, and the true/false statements from the date comparisons are accurate as well.
Your help is greatly appreciated.