$( document ).ready(function() { let items = []; let itemsRaw = []; $.getJSON('/api/books', function(data) { //let items = []; itemsRaw = data; $.each(data, function(i, val) { items.push('
  • ' + val.title + ' - ' + val.commentcount + ' comments
  • '); return ( i !== 14 ); }); if (items.length >= 15) { items.push('

    ...and '+ (data.length - 15)+' more!

    '); } $('