I try to filter the array with two conditions but without success, it only refers to the second condition, each condition individually works great.
The original task :
“When entering a text in the “search” text box, the users list will presents anly users that
their name or email contains that text
JavaScript
x
7
1
const filteredUsers = this.state.users.filter((filuser) => {
2
return (
3
filuser.name.toLowerCase().includes(this.state.searchfield.toLowerCase()) ||
4
filuser.email.toLowerCase().includes(this.state.searchfield.toLowerCase())
5
);
6
});
7
Advertisement
Answer
JavaScript
1
5
1
const filteredUsers = this.state.users.filter((filuser) => {
2
const {searchfield} = this.state
3
return (
4
`${filuser.name} ${filuser.email}`.toLowerCase().indexOf(searchfield)>-1
5
});