Here is an array of objects containing finalists:
finalistsCollection = [
{ name: 'Ann' , sections: [{id: '132', name: 'someName'}, {id: '456', name: 'someName'}] },
{ name: 'Jack' , sections: [{id: '798', name: 'someName'}] },
{ name: 'Morgan', sections: [{id: '456', name: 'someName'}] },
{ name: 'Billy', sections: [{id: '132', name: 'someName'}, {id: '456', name: 'someName'}]},
{ name: 'Monica', sections: [{id: '798', name: 'someName'}] }
]
I am attempting to filter this array based on the id value. Initially, I created a filtering function that checks if a sections
array has only one object:
filter(directionId) {
filteredCollection = this.finalistsCollection.filter((item) => item.sections[0].id === directionId
}
After applying the filter, I attempted to use the map()
function, but it still returned the entire array.