JSFiddle - React, Tailwind, and code Playground
by davixyz
HTML
<div id="log"></div>
JavaScript
var http_response = {
data : {
total : 987,
limit : 100
}
}
var offsets = [];
//offset param in a http request to achieve total of results
for(var i=0; i<http_response.data.total; i=i+http_response.data.limit){
offsets.push(i);
}
var stb = [];
stb.push("if total of results is = ", http_response.data.total, " and limit per page is ", http_response.data.limit, ", then number of pages is ", Math.ceil(http_response.data.total/http_response.data.limit),"<br /><br />")
//calculates the page
offsets.map(
function(offset){
stb.push(" when offset is ", offset, " active page is ",(offset/http_response.data.limit)+1, ", and results will be between ", offset," and ", offset+http_response.data.limit-1,"<br />");
}
);
document.getElementById('log').innerHTML = stb.join("");