javascript - Efficiently break an array every X number of values? -


i want split array group of values starting @ end , leaving beginning remander array. here's example of goal:

arr = [0,1,2,3,4,5,6,7,8,9,10,11] interval = 5 #chop output = [[0,1],[2,3,4,5,6],[7,8,9,10,11]] 

what's efficient way of doing this?

thanks help?

var arr = [0,1,2,3,4,5,6,7,8,9,10,11],     interval = 5,     output = [];  while (arr.length >= interval) {     output.unshift(arr.splice(-interval, interval)); } output.unshift(arr);  console.log(output); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -