I'd like to add a bulk of items into a sparse array, starting at a certain index. I came along this requirement in order to accomplish client side pagination while not retrieving all data from server (assuming server returns the right data, given the required indexes).
To keep right indexes when "Skipping" and "Taking", I need to store the items in a sparse array. Besides relevant indexes, other places in array might as well be
I wrote the following snippet of code, assuming
bulk is the retrieved chunk of items from Server, and
index is where the first item should be placed.
items = new Array(totalItemsPossibleCount); items = items.slice(-index) .concat(bulk) .concat(items.slice(index+bulk.length));
- Is there a shorter way to do so?
- Can this be achieved with underscore.js in more readable way?