I have a set of data where i need to format and render in HTML.
This is the data :
var data = [{
name: 'john',
age: 20,
department: 'financial',
group: 'groupA'
},
{
name: 'john',
age: 20,
department: 'healthcare',
group: 'groupA'
},
{
name: 'john',
age: 20,
department: 'insurance',
group: 'groupA'
},
{
name: 'john',
age: 20,
department: 'Realestate',
group: 'groupB'
}, {
name: 'Mark',
age: 20,
department: 'financial',
group: 'groupA'
},
{
name: 'Mark',
age: 21,
department: 'insurance',
group: 'groupA'
},
{
name: 'Mark',
age: 21,
department: 'financial',
group: 'groupB'
}
];
Here i have multiple users where he belongs to different groups and department.I want to format in such a way the if he belongs to same group then get the department which he belongs to in array and for other department show that as a new object.
The response should look like this:
var data_formatted = [
[{
name: 'john',
age: 20,
department: ['financial', 'healthcare', 'insurance'],
group: 'groupA'
},
{
name: 'john',
age: 20,
department: 'Realestate',
group: 'groupB'
}
],
[{
name: 'Mark',
age: 20,
department: ['financial', 'insurance'],
group: 'groupA'
},
{
name: 'Mark',
age: 21,
department: 'financial',
group: 'groupB'
}
]
];
Any suggestions Please!