I have a list in SharePoint online having more than 5000 items. How to deal it with JSOM or REST API.
In general, any query in JSOM/CSOM can work around the List View Threshold by setting the
RowLimit to some number under 5,000. If you actually need to retrieve more than 5,000 of the items, you will need to use the
ListItemCollectionPosition to "page" through the results in "chunks" so that any given queryExecute never exceeds the List View Threshold.
Suggest to create index column and then use it in Rest API endpoint or Caml, please check the similiar question here:
Another suggestion is to check the ItemsCount in the logic and use the $top parameter in Rest to control the items returned less than 5000: