Skip to content

Instantly share code, notes, and snippets.

@iptpv
Created January 28, 2015 13:28
Show Gist options
  • Save iptpv/f8ca0db895160c3bbf46 to your computer and use it in GitHub Desktop.
Save iptpv/f8ca0db895160c3bbf46 to your computer and use it in GitHub Desktop.
разбитие массива на определенное число массивов
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9],
columns = 3,
dataAr = [];
for (var colCount = 0, i = 0; colCount < data.length; colCount+=(data.length/columns), i++) {
dataAr[i] = data.slice(colCount, colCount + data.length/columns);
}
console.log(dataAr);
/**
* http://jsbin.com/jeqijolisa/1/
* /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment