If you're looking for a way to determine if "dog" is adjacent to "cat" in an array, there are a couple of methods you can use: Array.find or Array.some.
find
will return "dog" as truthy if it is next to "cat" in the array.
some
will return true if both "dog" and "cat" are found adjacent to each other, and false if not.
If you require a true/false function, you can use the following example:
const textArray = ['bird', 'dog', 'cat', 'snake', 'rabbit', 'ox', 'sheep', 'tiger'];
const areAdjacent = (word1, word2, arr) => arr
.some((word, i, arr) => word === word1 && arr[i+1] === word2);
console.log(areAdjacent("dog","cat",textArray))
console.log(areAdjacent("tiger","bird",textArray))
Another approach using Pilchard's example:
const textArray = ['bird', 'dog', 'cat', 'snake', 'rabbit', 'ox', 'sheep', 'tiger'];
const areAdjacent = (word1, word2, arr) => arr
.some((word, i, {[i+1]: nextWord}) => word === word1 && nextWord === word2);
console.log(areAdjacent("dog", "cat", textArray))
console.log(areAdjacent("tiger", "bird", textArray))