Tachyon
Tachyon

Reputation: 2411

Includes not finding character after space

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: Javascript debugger

Upvotes: 0

Views: 946

Answers (1)

Tristan De Oliveira
Tristan De Oliveira

Reputation: 808

Includes method is case sensitive So you need to lowercase everything when you want to search with case insensitive

Upvotes: 3

Related Questions