我有一个这样的数组
data = [
{ name : "sa", attributes : [{skin : "green"},{nose:"good"}]},
{ name : "sa", attributes : [{skin : "red"},{nose:"bad"}]},
{ name : "sa", attributes : [{skin : "green"},{nose:"good"}]},
{ name : "sa", attributes : [{nose:"good}]},
]
所以我想要基于皮肤属性的数组分组.我正在使用这样的下划线库
const attributeType = "skin";
const groupedCollections = _.groupBy(colls, (col) => {
const data = col.attributes.find((attribute) => {
const keys = Object.keys(attribute);
return keys.indexOf(attributeType) > -1 ? true : false
});
return data?.value
});
但这使得分组低于undefined
.
有什么帮助吗?