I have an array of people that I want to be able to search based of of their name. I have this working with the following code
{peopleArray
.filter((people) => {
if (
people.name.includes(searchParams)
)
{
return true;
}
return false;
})
.map((people) => (
//map the data here
I have an input that sets the value of what the user types in to be set to searchParams This is all working fine, however I want to have 2 inputs and to be able to search by both name and occupation
So I made another input to be set with jobSearchParams and updated my filter function like this
{peopleArray
.filter((people) => {
if (
people.name.includes(searchParams) || people.occupation.includes(jobSearchParams)
)
{
return true;
}
return false;
})
However the second filtering doesn't work at all. When the second input has a value the array does not change at all. I have console.log()'d to show that the input is passing the value to jobSearchParam but still the array does not change.
For more info, the peopleArray looks like this
{
name: "Bob",
occupation: ["builder", "developer"]
}
The searchBox values are set at the inputs like so
<input className="nameSearch"
placeholder="Search by Job"
value={jobSearchParam}
onInput={(e ) => setJobSearchParam(e.target.value)}
/>
let filteredArray = peopleArray.filter(person => person.name.includes(searchParams) || person.occupation.includes(jobSearchParams));. you can solve this in a single line of code