[Solved] How to chunk an array based on another array of numbers?


You could push sliced parts to the result.

let array = [1, 2, 2],
    objlist = [{ name: 'dummy' }, { name: 'new' }, { name: 'news' }, { name: 'place' }, { name: 'place' }],
    result = [],
    i = 0,
    j = 0;
    
while (j < array.length) {
    result.push(objlist.slice(i, i += array[j++]));
}

console.log(result);

solved How to chunk an array based on another array of numbers?