Reputation: 2411
I am trying to do a simple javascript .includes()
check on a string to see whether or not a name contains a specific letter.
The code I currently have is as follows:
this.recipients = this.originalRecipients.filter((item) => {
let test = item.name.includes(val);
return item.name.includes(val);
});
But it would seem that if the name contains a space, includes()
won't match after the space. I.e. if I have the name, Landry Farrell
and the letter I am checking for is f
includes()
returns false.
You can see that in this screenshot when the debugger was hit, in this case val
was f
:
Upvotes: 0
Views: 946
Reputation: 808
Includes method is case sensitive So you need to lowercase everything when you want to search with case insensitive
Upvotes: 3