Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function splitArrayInArraysBySection (arr) {
const returnsObject = arr.reduce((newArrSofar, item) => {
const toAdd = newArrSofar[item.section] ? [...newArrSofar[item.section], item] : [item]
return {
[item.section]: toAdd
return Object.values(returnsObject); // to return array actually
const check = [
{id: 'a', section: 0},
{id: 'b', section: 1},
{id: 'c', section: 2},
{id: 'd', section: 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.