const results = searchTerm || searchTerm2 ? !searchTerm2 ? people.filter(person => person.name.toLowerCase().includes(searchTerm.toLocaleLowerCase()) ) : people.filter( person => person.address.toLowerCase() === searchTerm2.toLocaleLowerCase() ) : people;
i came up with this solution and it works now but only if one of the conditions is true. I want to make the method filter the two conditions in the same time. So like i want to know all the people that their name is Alex and lives in New york
For your specific case you can do like this:
const results = searchTerm && searchTerm2 ? people.filter(person => person.name.toLowerCase().includes(searchTerm.toLocaleLowerCase()) && person.address.toLowerCase().includes(searchTerm2.toLocaleLowerCase()) ) : people
However, note that the filter won't be applied unless both search terms are present.
Yah but that is exactly what i don't want. I want that the user can choose one of the filters or both of them in the sametime
Hello! In the end you found the solution?
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
i came up with this solution and it works now but only if one of the conditions is true. I want to make the method filter the two conditions in the same time. So like i want to know all the people that their name is Alex and lives in New york
For your specific case you can do like this:
However, note that the filter won't be applied unless both search terms are present.
Yah but that is exactly what i don't want. I want that the user can choose one of the filters or both of them in the sametime
Hello! In the end you found the solution?