0

How can i check array match string for example

var blocklist = ['jack','mark','jhon','fox'];

var str = "xxxxxxxxxxjackxxxxxxxxx";

How can i check for var str that not match array blocklist?

3
  • you mean , you want to know if string contains anything present in the array? Commented Feb 21, 2020 at 10:31
  • str not includes words in blocklist Commented Feb 21, 2020 at 10:33
  • Please check this once . blocklist.forEach(ele => { if(str.indexOf(ele)!==-1){ console.log('yes');} }); if the string contains anything in present in the array , it will console ' yes' Commented Feb 21, 2020 at 10:36

1 Answer 1

0

You could find the string by using Array#includes.

var blocklist = ['jack', 'mark', 'jhon', 'fox'],
    str = "xxxxxxxxxxjackxxxxxxxxx",
    result = blocklist.find(s => str.includes(s));

console.log(result);

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.