mardi 30 août 2016

Lodash - Chunks of an Array of objects using an object property as the "delimiter"

Given the following array:

var arr = [{id:1 , code:0},
           {id:1 , code:12},
           {id:1 , code:0},
           {id:1 , code:0},
           {id:1 , code:5}];

How can I use lodash, to split the array each time code is not equal to 0 and get the following results?

[
 [{id:1 , code:0},{id:1 , code:12}],
 [{id:1 , code:0},{id:1 , code:0},{id:1 , code:5}]
]




Aucun commentaire:

Enregistrer un commentaire