What seemed like a simple task has me puzzled. I'm trying to sort through an array of objects based on user input.
[{ name: Stan, age: 20, height: 190 },
{ name: Pan, age: 30, height: 180 },
{ name: Dan, age: 28, height: 185 },
{ name: San, age: 20, height: 170 }]
For example, if a user types 'S', they should get 'Stan' and 'San'. If they type 'St', it should narrow down to just 'Stan', and so on with real-time results displayed.
I've attempted to filter the array by first letter and then try to refine it further based on subsequent inputs by pushing results into another array, but it's not working as expected. So now, I find myself at a standstill.
filterCat() {
this.cate.filter(cat => {
if (cat.name.startsWith(this.searchTerm.toUpperCase())) {
this.tempSearchStore.push(cat);
console.log('cats', cat);
}
// This displays all cats based on the first letter entered.
});
}
This is my HTML:
<ion-searchbar animated [(ngModel)]="searchTerm" debounce="1000"
(ionChange)="filterCat()" mode="ios">
</ion-searchbar>