Below is an array containing JSON objects:
items = [
{
id: '1',
name: 'Josh',
transactionDate: '2012-08-10',
creditAmount: '200',
numberBank: '12345',
},
{
id: '1',
name: 'Josh',
transactionDate: '2012-08-14',
creditAmount: '159',
numberBank: '12345',
},
{
id: '1',
name: 'Josh',
transactionDate: '2012-08-15',
creditAmount: '3421',
numberBank: '12345',
},
{
id: '2',
name: 'George',
transactionDate: '2012-09-15',
creditAmount: '6000',
numberBank: '13345',
},
{
id: '2',
name: 'George',
transactionDate: '2012-09-16',
creditAmount: '6565',
numberBank: '13345',
}
]
I need to group the array by the same id
:
For example:
[
{
id: '1',
name: 'Josh',
transactionDate: '2012-08-10',
creditAmount: '200',
numberBank: '12345',
},
{
id: '1',
name: 'Josh',
transactionDate: '2012-08-14',
creditAmount: '159',
numberBank: '12345',
},
{
id: '1',
name: 'Josh',
transactionDate: '2012-08-15',
creditAmount: '3421',
numberBank: '12345',
}
],
[
{
id: '2',
name: 'George',
transactionDate: '2012-09-15',
creditAmount: '6000',
numberBank: '13345',
},
{
id: '2',
name: 'George',
transactionDate: '2012-09-16',
creditAmount: '6565',
numberBank: '13345',
}
]
Is there any way to achieve this? Thank you.