I have this data script:
var data = [
{
'name': 'social-button',
'group': null
}, {
'name': 'social-button',
'group': null
}, {
'name': 'social-button',
'group': 'buttons'
}, {
'name': 'social-button',
'group': null
}, {
'name': 'icon',
'group': 'icons'
}, {
'name': 'other',
'group': null
}, {
'name': 'icon',
'group': null
}
];
I would like to normalize this data:
var data = [
{
'name': 'social-button',
'group': 'buttons'
}, {
'name': 'social-button',
'group': 'buttons'
}, {
'name': 'social-button',
'group': 'buttons'
}, {
'name': 'social-button',
'group': 'buttons'
}, {
'name': 'icon',
'group': 'icons'
}, {
'name': 'other',
'group': null
}, {
'name': 'icon',
'group': 'icons'
}
];
Basically, I would like to ensure that every element having the same nameshould also have the same group, if only one of them has one.
Can any node module help with this?
Or maybe there is some kind of smart way to do this?