var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49];
var n = 4;
var result;
result = Array(Math.ceil(a.length / 4)).fill(0).map( (v, i) => a.slice(i*n, (i+1)*n) );
result = Array(Math.ceil(a.length / 4)).fill(0).map( (v, i, array) => ( l = a.slice(i*n, (i+1)*n) ).concat( Array( Math.max(0, n - l.length) ).fill(0) ) );
const getChunks = (arr, chunkSize) =>
Array.from(
{ length: Math.ceil(arr.length / chunkSize) },
(n, i) => arr.slice(i * chunkSize, (i + 1) * chunkSize)
);
// или
const getChunks = (arr, chunkSize) =>
arr.reduce((acc, n, i) => (
i = i / chunkSize | 0,
(acc[i] = acc[i] || []).push(n),
acc
), []);
// или
const getChunks = (arr, chunkSize) =>
arr.reduce((acc, n, i) => (
(i % chunkSize) || acc.push([]),
acc[acc.length - 1].push(n),
acc
), []);
const arr = [...Array(50).keys()];
const chunks = getChunks(arr, 7);
serialize = function(obj, prefix) {
var str = [], p;
for(p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push((v !== null && typeof v === "object") ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}
console.log(serialize({foo: "hi there", bar: { blah: 123, quux: [1, 2, 3] }}));
// foo=hi%20there&bar%5Bblah%5D=123&bar%5Bquux%5D%5B0%5D=1&bar%5Bquux%5D%5B1%5D=2&bar%5Bquux%5D%5B2%5D=3
document.querySelector('.push-to-add').previousSibling
console.dir(document.querySelector('.push-to-add').parentElement.childNodes)
</section><button class="push-to-add">