我有一个方面,结果如下:
{
directConfigs: [
type: "Type A",
result: {
priority: 2,
id: ObjectId('63c6a4b858612f44f37d4771')
},
type: "Type B",
result: {
priority: 3,
id: ObjectId('63bd7878f1f085f7d8a6827f')
}
],
indirectConfigs: [
type: "Type A",
result: {
priority: 1,
id: ObjectId('627279d3ba7aef5d6418c867')
},
type: "Type C",
result: {
priority: 5,
id: ObjectId('63be730bf1f085f7d8a682c8')
}
],
}
从这个结果中,我希望获得在type
字段上分组的对象列表.规则是directConfigs
优先于indirectConfigs
.因此,如果两个数组都具有类型A配置,则我们需要directConfigs
中的那个.我已经确保每个类型在每个数组中只能出现一次.结果应该如下所示:
result: [
{
type: "Type A",
result: {
priority: 2,
id: ObjectId('63c6a4b858612f44f37d4771')
}
},
{
type: "Type B",
result: {
priority: 3,
id: ObjectId('63bd7878f1f085f7d8a6827f')
}
},
{
type: "Type C",
result: {
priority: 5,
id: ObjectId('63be730bf1f085f7d8a682c8')
}
}
]
我该怎么做?