JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

function inArray(array1, array2) {
  let res = array1.filter(function(word, num) {
    for (let i = 0; i < array2.length; i++) {
      //console.log(word, array2[i], word.indexOf('xyzz'));
      if (word.indexOf(array2[i]) !== -1) { //почему условие не работает?
        return array1[num];
      }
    }
  });
  return res;
}

a2 = ["xyzz", "alive", "harp", "sharp", "armstrong"]

a1 = ["xyz", "live", "strong"]

console.log(inArray(a1, a2));