I have an issue and the way to solve it is by grouping the elements in my array based on their properties (the ID). Let me explain :
This is the given array :
[ { project_id: 'project:710f57c6bb18753dfeaad60b7a7437df',
end_date: '2017-05-18',
invoice_method: 'FixedFee',
amount: '1.000000',
price: '134.000000' },
{ project_id: 'project:710f57c6bb18753dfeaad60b7a7437df',
start_date: '2017-06-01',
subscription_cycle: 'Month',
invoice_method: 'Subscription',
amount: '1.000000',
price: '49.000000' },
{ project_id: 'project:abcdefghijklmnop',
start_date: '2017-06-01',
subscription_cycle: 'Month',
invoice_method: 'Subscription',
amount: '1.000000',
price: '49.000000'},
{ project_id: 'project:abcdefghijklmnop',
start_date: '2017-06-01',
subscription_cycle: 'Month',
invoice_method: 'Subscription',
amount: '1.000000',
price: '49.000000'},
]
The first 2 elements in this big array have the same ID and the last 2 have the same ID, so the output I would like is something like :
//MAIN ARRAY
[
//ONE CHUNK
[
{ project_id: 'project:710f57c6bb18753dfeaad60b7a7437df',
end_date: '2017-05-18',
invoice_method: 'FixedFee',
amount: '1.000000',
price: '134.000000' },
{ project_id: 'project:710f57c6bb18753dfeaad60b7a7437df',
start_date: '2017-06-01',
subscription_cycle: 'Month',
invoice_method: 'Subscription',
amount: '1.000000',
price: '49.000000' }
]
//ONE CHUNK
[
{ project_id: 'project:abcdefghijklmnop',
start_date: '2017-06-01',
subscription_cycle: 'Month',
invoice_method: 'Subscription',
amount: '1.000000',
price: '49.000000'},
{ project_id: 'project:abcdefghijklmnop',
start_date: '2017-06-01',
subscription_cycle: 'Month',
invoice_method: 'Subscription',
amount: '1.000000',
price: '49.000000'}
]
]