I get an array of objects:
const inputStructure = [
{
state: 'LA',
insurance: 'Test1'
},
{
state: 'LA',
insurance: 'Test2'
},
{
state: 'TX',
insurance: 'Test3'
}
]
How can I group objects with the same state property?
I need to create a function which would return the following result:
const outputStructure = {
'LA': {
state: 'LA',
insurances: ['Test1', 'Test2']
},
'TX': {
state: 'TX',
insurances: ['Test3']
}
}
ObjectandArray.maporreducefunctions? These methods will help you iterate over the structure and create the new structure that you want.groupByfunction, and it's easy to write your own as seen in the duplicate.