I have an array of data with start and end date which is being displayed in angular calendar. I would like to filter the array based on the start and end date.
0: {id: 86, start_date: "2019-11-06T09:00:13Z", end_date: "2019-11-11T14:00:13Z"}
1: {id: 86, start_date: "2019-11-04T18:30:00Z", end_date: "2019-11-07T07:12:09Z"}
2: {id: 86, start_date: "2019-11-04T18:30:00Z", end_date: "2019-11-07T07:03:21Z"}
3: {id: 86, start_date: "2019-11-26T18:30:00Z", end_date: "2019-11-27T07:03:21Z"}
4: {id: 66, start_date: "2019-11-04T18:30:00Z", end_date: "2019-11-07T07:12:09Z"}
5: {id: 66, start_date: "2019-11-05T18:30:00Z", end_date: "2019-11-12T07:03:21Z"}
If I am on day 2019-11-07 (I couldn't get the date from here for filter) I want to build an array like this from above without using the 2019-11-07
0: {id: 86, start_date: "2019-11-06T09:00:13Z", end_date: "2019-11-11T14:00:13Z"}
1: {id: 66, start_date: "2019-11-04T18:30:00Z", end_date: "2019-11-07T07:12:09Z"}
The following is the filter i have written
data.forEach((item, index) => {
if (index !== data['results'].findIndex(i => i.id === item.id &&
new Date(i.start_date).toDateString() === new Date(item.start_date).toDateString() &&
new Date(i.end_date).toDateString() === new Date(item.end_date).toDateString())) {
data.splice(index, 1);
}
});
console.log(data);
If I am on 2019-11-07, i am not able to remove this item
0: {id: 86, start_date: "2019-11-06T09:00:13Z", end_date: "2019-11-11T14:00:13Z"}
Can anyone help me?
.forEach(),.findIndex()and.splice()and not a simple.filter()?