Given this JS object list:
var items = [
{
'name':'a',
'id':'ab-1',
'attr':'value1'
},
{
'name':'c',
'id':'ab-2',
'attr':'value0'
},
{
'name':'z',
'id':'ab-1',
'attr':'value2'
},
{
'name':'t',
'id':'ab-2',
'attr':'value3'
}
]
Is there a nice way to create a list of lists where each list contains objects with common id, like so:
var items = [
[
{
'name':'a',
'id':'ab-1',
'attr':'value1'
},
{
'name':'z',
'id':'ab-1',
'attr':'value2'
}],
[
{
'name':'c',
'id':'ab-2',
'attr':'value0'
},
{
'name':'t',
'id':'ab-2',
'attr':'value3'
} ]
]
I can only think of looping through all items first to create a list of unique ids (let's call it id-list) and then looping through all items again this time creating a list for each item in id-list.