【发布时间】:2017-05-21 07:08:56
【问题描述】:
我有这个数据场景:
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
}
];
我想将此数据标准化为:
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'
}
];
所以基本上,我想确保具有相同name 的每个元素也应该具有相同的group,如果只有一个相同的元素有一个。
是否存在一些节点模块可以帮助解决这个问题?
或者,是否存在一些聪明的方法来做到这一点?
【问题讨论】:
标签: javascript arrays node.js normalization