I know that some would mark this is a duplicate, but in my case (and my limited knowledge) i still haven't found any similar example which i can relate to.. Therefore i say sorry upfront :)
It's pretty straight forward for an experienced JS dev i assume..
I just cannot figure out how to match on a arrays property :
if (!uniqueEnts.includes(ent.entity)) { // how do i match on uniqueEnts.entityName ?
Current approach results in too many hits in the new list, and the check (look above) doesn't provide with the correct check against uniqueEnts.entityName
Desired output : new list (uniqueEntities) with the following two properties
- entityName (unique)
- entityColor (randomly generated)
Code :
uniqueEntities() {
let uniqueEnts = []
this.nluDataUnfiltered.forEach(function (i) {
i.entities.forEach(function (ent) {
if (!uniqueEnts.includes(ent.entity)) {
let obj = {
entityName: ent.entity,
entityColor: Util.getRandomColor()
}
uniqueEnts.push(obj)
obj = null
}
})
})
return _uniqueEnts.entityName.sort().value()
// earlier tryout --> return _(uniq(uniqueEnts.entityName)).sort().value()
},
UPDATED WITH LATEST TRYOUT :
uniqueEntities() {
let uniqueEntityObj
var uniqueEntity = Array.from(new Set( data.map(el => this.nluDataUnfiltered.entities[0].entity) ));
uniqueEntityObj = uniqueEntity.map(el => {
entityName:el,
entityColor: Util.getRandomColor()
});
return uniqueEntityObj
},