I have an array like this
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}]},
]
so i want the grouping of array based on skin attribute. I am using _ underscore library like this
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
});
but this is making grouping under undefined.
Any help?
keys.includesinstead ofkeys.indexOf?