Is there a way to display only the top 3 results using the .slice function after applying the filter function?
I attempted to add .slice after the match in the filter function, but it didn't work as expected.
Here is the code snippet:
filteredEntitySearch () {
let entity = this.options
return entity.filter((entity) => {
return entity.name.match(this.searchQuery).slice(0, 4)
})
},
Just to provide some context, the filteredEntitySearch function is intended for:
- Retrieving all entities that match the search query (searchQuery)
- Displaying only the top 3 results
Any assistance on how to achieve this would be greatly appreciated. Thank you!