Here are two ways to check if an array of strings contains a substring in JavaScript.
- Using includes() method and some() method
- Using includes() method and filter() method
Method 1: Using includes() method and some() method
The some() method is used to check whether at least one element in the array passes the test implemented by the provided function. In this case, we will use the includes() method within the some() method to check if any string in the array contains the given substring.
const arr = ["apple", "banana", "cherry", "date", "fig"];
const subStr = "an";
const hasSubstring = arr.some(word => word.includes(subStr));
console.log(hasSubstring);
Output
true
Method 2: Using includes() method and filter() method
The includes() method is used to check whether one string may be found within another string, returning true or false as appropriate. Combined with the filter() method, it creates a new array with all elements that pass the test implemented by the provided function.
const arr = ["apple", "banana", "cherry", "date", "fig"];
const subStr = "ry";
const result = arr.filter(word => word.includes(subStr));
console.log(result);
Output
[ 'cherry' ]
Conclusion
Use filter() and includes() when you want to get all the strings that contain a particular substring.
Use some() and includes() when you just want to know if any string in the array contains the substring.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.