Skip to content

Instantly share code, notes, and snippets.

@filipelinhares
Created June 20, 2017 05:48
Show Gist options
  • Save filipelinhares/3fdfd808d3f8c7004c7c711e32536d47 to your computer and use it in GitHub Desktop.
Save filipelinhares/3fdfd808d3f8c7004c7c711e32536d47 to your computer and use it in GitHub Desktop.
Pagination with Javascript
function listItems(items, pageActual, limitItems){
let result = [];
let totalPage = Math.ceil( items.length / limitItems );
let count = ( pageActual * limitItems ) - limitItems;
let delimiter = count + limitItems;
if(pageActual <= totalPage){
for(let i=count; i<delimiter; i++){
if(items[i] != null){
result.push(items[i]);
}
count++;
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment