-1

I am scripting automation in Javascript, using jest and puppeteer right now, and I want to verify a name, for example;

I have a name of const name = Watson, James R. and wanted to compare the name const info_name = Watson James , which we can hypothetically say that they are the same person. When I was using python and selenium I usually use, in just to check the presence of a letter or word inside a string or list, so my question is, what is the best function I can use?

I saw the use of .includes but it is too "case sensitive" one different character and it gives off "False" result. Also I saw .some but I get an error of ".some is not a function".

What can I use for alternatives? I would gladly appreciate your replies, Thank you in advance!

3
  • 2
    post the code that shows the error to you. Commented Aug 8, 2021 at 16:10
  • You mean you want to check if substrings of info_name (e.g. "Watson") are contained in name? Commented Aug 8, 2021 at 16:14
  • 2
    What you explain sounds like a case insensitive, fuzzy search. I don’t think this exists in js. Can you post examples of what should match and what shouldn’t? Commented Aug 8, 2021 at 16:15

1 Answer 1

1

The equivalent of in with JavaScript is .includes.
In order to ignore case sensitivity you can convert both strings to lower case with .toLowerCase() and then apply .includes.

console.log(string.toLowerCase().includes(substring.toLowerCase()));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.