1

My web app has a search box. Currently the code searches a bunch of fields, but it only returns results from one field. How do I make it so that I can search in multiple fields separated by a comma or semicolon?

CODE EXAMPLE:

return this.builds.sort(compare).filter((build) => {
            return build.title.toLowerCase().match(this.search.toLowerCase()) || build.item1.toLowerCase().match(this.search.toLowerCase()) ||
            build.item2.toLowerCase().match(this.search.toLowerCase()) || build.item3.toLowerCase().match(this.search.toLowerCase()) ||
            build.item4.toLowerCase().match(this.search.toLowerCase())
        }

For example: one build has a title of "BEST EVER" and another build has an item2 of "THE RED ONE". I would like to be able to search "BEST, RED" and have them both show up.

I have no idea how to accomplish this - can anyone enlighten me?

Thanks

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164

0 Answers0