Answers for "javascript, if array contains"

1

js check if string includes from array

const found = arrayOfStrings.find(v => str.includes(v));
Posted by: Guest on October-13-2021
0

js check if string includes from array

function buildSearch(substrings) {
  return new RegExp(
    substrings
    .map(function (s) {return s.replace(/[.*+?^${}()|[]\]/g, '\$&');})
    .join('{1,}|') + '{1,}'
  );
}


var pattern = buildSearch(['hello','world']);

console.log(pattern.test('hello there'));
console.log(pattern.test('what a wonderful world'));
console.log(pattern.test('my name is ...'));
Posted by: Guest on October-14-2021

Code answers related to "javascript, if array contains"

Code answers related to "Javascript"

Browse Popular Code Answers by Language