I would like to group objects by key mod
. I have this array:
const testArray = [
{cor: 'yellow', peso: 2, seq: 1, mod: 'normal'},
{cor: 'yellow', peso: 2, seq: 2, mod: 'normal'},
{cor: 'yellow', peso: 3, seq: 3, mod: 'abstract'},
{cor: 'verde', peso: 5, seq: 4, mod: 'normal'},
{cor: 'yellow', peso: 4, seq: 5, mod: 'abstract'},
{cor: 'green', peso: 8, seq: 6, mod: 'abstract'},
{cor: 'yellow', peso: 9, seq: 7, mod: 'normal'}
]
and i expect to create a new array with this objects like this:
const groupArray = [
[
{cor: 'yellow', peso: 2, seq: 1, mod: 'normal'},
{cor: 'yellow', peso: 2, seq: 2, mod: 'normal'},
{cor: 'yellow', peso: 9, seq: 7, mod: 'normal'}
],
[
{cor: 'yellow', peso: 4, seq: 5, mod: 'abstract'},
{cor: 'yellow', peso: 3, seq: 3, mod: 'abstract'},
]
];
Someone could help me? I tried with .map
anda .filter
but does't works.