...
/Searching Over Multiple Properties
Searching Over Multiple Properties
Learn how to extend your generic search function to support searching for multiple object properties simultaneously.
We'll cover the following...
We'll cover the following...
We currently have a genericSearch function that can filter properties of type string or number for any object. However, the disadvantage of this implementation is that it can only search using a single property of an object. An improved generic search would be able to accept one or more properties. For example, if we want to search both the title and description of our widgets, our call to genericSearch might look something like this:
{widgets.filter(() => genericSearch(widget, ["title", "description"], query)).map(widget => {...})}
Implementation
Let’s hop back into genericSearch.ts to implement this functionality.
The first change we’ll make is in the signature. ...