I have a list of dates and I'm attempting to filter out dates that fall outside of a specific date range. However, I'm encountering an issue where some dates before the "from" date are still present in the filtered list. What could be causing this problem?
$scope.filterUpcomingEvents = function() {
$scope.arrayOfEventData = JSON.parse(JSON.stringify($scope.tempArray));
console.log($scope.tempArray, "arrayofeve");
for (let d = 0; d < $scope.arrayOfEventData.length; d++) {
debugger;
console.log(d);
console.log(new Date($scope.tempArray[d].event_date), "from", $scope.upcomingEventFrom);
console.log(new Date($scope.tempArray[d].event_date) < $scope.upcomingEventFrom);
console.log(new Date($scope.tempArray[d].event_date), "to", $scope.upcomingEventTo);
console.log(new Date($scope.tempArray[d].event_date) > $scope.upcomingEventTo);
console.log("---");
if (new Date($scope.arrayOfEventData[d].event_date) < $scope.upcomingEventFrom || new Date($scope.arrayOfEventData[d].event_date) > $scope.upcomingEventTo) {
$scope.arrayOfEventData.splice(d, 1);
}
}
console.log($scope.arrayOfEventData, "after splice");
}
Despite receiving true results for some comparisons in the console, the specified values are not being removed when checking the final array afterwards.
List of dates:
0: {
event_id: "49",
event_name: "julyevent",
event_date: "2018-07-13",
event_time: "11:00AM",
event_type_id: "2",
…
}
1: {
event_id: "50",
event_name: "up event1",
event_date: "2018-06-22",
event_time: "11:11AM",
event_type_id: "2",
…
}
2: {
event_id: "52",
event_name: "twe",
event_date: "2018-06-29",
event_time: "11:11AM",
event_type_id: "2",
…
}
3: {
event_id: "55",
event_name: "eve4",
event_date: "2018-06-23",
event_time: "10:22PM",
event_type_id: "2",
…
}
4: {
event_id: "56",
event_name: "eve5",
event_date: "2018-06-25",
event_time: "11:11AM",
event_type_id: "2",
…
}
5: {
event_id: "57",
event_name: "eve6",
event_date: "2018-06-28",
event_time: "10:00AM",
event_type_id: "2",
…
}
6: {
event_id: "58",
event_name: "eve7",
event_date: "2018-06-28",
event_time: "9:00AM",
event_type_id: "2",
…
}
7: {
event_id: "59",
event_name: "eve8",
event_date: "2018-07-12",
event_time: "7:00AM",
event_type_id: "2",
…
}
8: {
event_id: "60",
event_name: "eve9",
event_date: "2018-06-19",
event_time: "4:00AM",
event_type_id: "2",
…
}
9: {
event_id: "61",
event_name: "eve10",
event_date: "2018-06-20",
event_time: "8:00PM",
event_type_id: "2",
…
}
10: {
event_id: "62",
event_name: "eve11",
event_date: "2018-06-23",
event_time: "3:00AM",
event_type_id: "2",
…
}
11: {
event_id: "63",
event_name: "eve12",
event_date: "2018-06-21",
event_time: "10:22PM",
event_type_id: "2",
…
}
12: {
event_id: "64",
event_name: "eve13",
event_date: "2018-06-24",
event_time: "6:00AM",
event_type_id: "2",
…
}