I'm new to Javascript. I'm using the example here
const pageLimit = 3; //to avoid infinite loops!
let page = 1;
let allData = ;for(page; page < pageLimit; page++){
//fetch data
const currentPageData = await gethuduAssetsLayouts.trigger({additionalScope: {page}});//append recently fetched data
allData = [...allData, ...currentPageData.data];
//allData = [allData, currentPageData.data];//check if this is the last page and exit the loop if so
if(page === pageLimit) break;
}if(page === pageLimit) console.log("Page limit reached");
return allData;
My API returns 25 results at a time. I have a total of 32. It does not provide any page numbers or total count or searching.
When I run the code I get the first 25 results and then an error "query7: currentPageData.data is undefined."
If I take the ... off the allData array, I can see the table show 25, then change to 8. I know this will not work because the ... is used to amend the array. But it does show me that is it looping.
Any help would be greatly appreciated. I know I'm close.