I've got an array of objects as follows:
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'}] }
]
How to filter this array by id value? For now, I've made filtering if a sections
array has only one object inside:
filter(directionId) {
filteredCollection = this.finalistsCollection.filter((item) => item.sections[0].id === directionId
}
I've tried to use map()
function after the filter, but it still returns the whole array.