0

I am trying to check if an array of substrings present in an array of strings. Tried using some() which is basically looking if any one of the substring is present. In below case it is returning true in both cases as 'Apple' is present in both strings but 'Hi' is not there. Basically, I wanted to make sure all the given substrings are present in an array of strings. Is there a better way to write it? Using every() instead of some() did not helped me as it looks for all the substrings in each string. If I use every() it returning false every time.

Strings = ['Hello I am an Apple', 'An Apple a day'];
subStrings = ['Apple', 'Hi'];
for (const stng of Strings) {
  subStrings.some((subString) => stng.includes(subString))
}
Ray
  • 15
  • 6
  • consider using `every` instead of `some` – Daniel A. White Sep 14 '22 at 15:37
  • I am looping through each string. If I use `every()` it will look for two subStrings in each string. In my case having any one of the subStrings in a string is ok but at the end of loop all the substrings should be there. – Ray Sep 14 '22 at 15:51

0 Answers0