Comparing two values of an array object and then alerting user

I have the following JSFiddle (https://jsfiddle.net/walker123/jzsuntx3/23/) and the console.log(selectedRows); of the following click function prints the object.

$('#jqxbutton').click(function () {
                var rows = $('#jqxgrid').jqxGrid('getrows');
            
                var selectedRows = rows.filter(x => x.available)
                
              
                for(let i = 0; i < selectedRows.length; i++) {
                    
                    
                    if (selectedRows[i].yeareligible === "N" && selectedRows[i].startyearValue === null && selectedRows[i].endyearValue ===  null ) {
                        selectedRows[i].startyearValue = -1;
                        selectedRows[i].endyearValue = -1;
                    
                    }
                    else if (selectedRows[i].yeareligible === "Y" && selectedRows[i].startyearValue === null && selectedRows[i].endyearValue === null ) {
                        selectedRows[i].startyearValue = '2015';
                        selectedRows[i].endyearValue = '2021';

                     
                    }

                }
                console.log(selectedRows);
                 
                $('#jqxgrid').jqxGrid('clearselection');
                //var selectedRows = $('#jqxgrid').jqxGrid('getselectedrowindex');
                //checkIfThereAreSelectedRows(selectedRows);

            });

For example, if I select the following items:

I see the following object after hitting the button:


[{
  available: true,
  boundindex: 1,
  endyearValue: "2010",
  firstname: "Elio",
  startyearValue: "2012",
  uid: 1,
  uniqueid: "2822-19-21-27-182626",
  visibleindex: 1,
  yeareligible: "Y"
}, {
  available: true,
  boundindex: 3,
  endyearValue: "2013",
  firstname: "Elio",
  startyearValue: "2011",
  uid: 3,
  uniqueid: "2420-19-28-30-241920",
  visibleindex: 3,
  yeareligible: "Y"
}]

Is it possible to validate using javascript the startyearValue and endyearValue from each of the array and in case startyearValue is greater than endYearValue, show an alert to the user with following message:

alert("Some of your selections have start year greater than end year, please check and make sure start year is always less than end year")

Basically, I don’t want to send this object array to an Ajax call if any of the array contains startyearValue greater than endyearValue. For example, in the above example, the first array contains startyearValue of 2012 and endYearValue of 2010.

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.