How validate the dates?

I am comparing the dates wherein the next object created should not have the dates between the date present in my database objects. For that, I have created a validation

 $scope.shiftTypeValues.forEach(function (shift) {
                    if ((shift.endDate >= item.endDate || shift.endDate >= item.startDate)) {
                        window.alert("There is another shift between that date! Please select another shift");
                        found = true;
                    }
            });

Here, $scope.shiftTypeValues are the objects in my database and item are the current object for which I am checking the date. Right now I am comparing the end dates with the current item start date and end date but suppose I save the date as

    Start Date              End Date
1.) Feb 16,2022             Feb 19,2022
2.) Feb 20,2022             Feb 24,2022

Now, if I edit the first date and save the date as 18Feb,2022 which should save since there is no shift falling under that date but my condition is checking the end date so 24 feb > 19 feb and it is showing alert? So, what should I check in order to save my object?