Home > Software design >  Ionic, javascript search items in lowercase
Ionic, javascript search items in lowercase

Time:11-10

Have a list of times, capitalized. How can i do to find them if input text is in lowercase?

ex: Barcelona, when input "bar", find it. Try with .lowercase() but doesn't works

onSearch(text){
    if(text){
      const filter_data=this.old_locations.filter((element) => element.title.includes(text));
      this.locations=filter_data;
    }else{
      this.locations=this.old_locations;
    }
  }

CodePudding user response:

How about this

this.locations = text ? this.old_locations
  .filter(element => element.title.toLowerCase().includes(text.toLowerCase())) :
  this.old_locations;

Save some cycles by lowercasing text first

  • Related