You can use the .some method referenced here.

The some() method tests whether at least one element in the array passes the test implemented by the provided function.

// test cases
const str1 = 'hi hello, how do you do?';
const str2 = 'regular string';
const str3 = 'hello there';

// do the test strings contain these terms?
const conditions = ["hello", "hi", "howdy"];

// run the tests against every element in the array
const test1 = conditions.some(el => str1.includes(el));
const test2 = conditions.some(el => str2.includes(el));
// strictly check that contains 1 and only one match
const test3 = conditions.reduce((a,c) => a + str3.includes(c), 0) == 1;

// display results
console.log(`Loose matching, 2 matches "${str1}" => ${test1}`);
console.log(`Loose matching, 0 matches "${str2}" => ${test2}`);
console.log(`Exact matching, 1 matches "${str3}" => ${test3}`);

Also, as a user mentions below, it is also interesting to match "exactly one" appearance like mentioned above (and requested by OP). This can be done similarly counting the intersections with .reduce and checking later that they're equal to 1.

Answer from dinigo on Stack Overflow
Top answer
1 of 16
418

You can use the .some method referenced here.

The some() method tests whether at least one element in the array passes the test implemented by the provided function.

// test cases
const str1 = 'hi hello, how do you do?';
const str2 = 'regular string';
const str3 = 'hello there';

// do the test strings contain these terms?
const conditions = ["hello", "hi", "howdy"];

// run the tests against every element in the array
const test1 = conditions.some(el => str1.includes(el));
const test2 = conditions.some(el => str2.includes(el));
// strictly check that contains 1 and only one match
const test3 = conditions.reduce((a,c) => a + str3.includes(c), 0) == 1;

// display results
console.log(`Loose matching, 2 matches "${str1}" => ${test1}`);
console.log(`Loose matching, 0 matches "${str2}" => ${test2}`);
console.log(`Exact matching, 1 matches "${str3}" => ${test3}`);

Also, as a user mentions below, it is also interesting to match "exactly one" appearance like mentioned above (and requested by OP). This can be done similarly counting the intersections with .reduce and checking later that they're equal to 1.

2 of 16
80

With includes(), no, but you can achieve the same thing with REGEX via test():

var value = /hello|hi|howdy/.test(str);

Or, if the words are coming from a dynamic source:

var words = ['hello', 'hi', 'howdy'];
var value = new RegExp(words.join('|')).test(str);

The REGEX approach is a better idea because it allows you to match the words as actual words, not substrings of other words. You just need the word boundary marker \b, so:

var str = 'hilly';
var value = str.includes('hi'); //true, even though the word 'hi' isn't found
var value = /\bhi\b/.test(str); //false - 'hi' appears but not as its own word
🌐
JsCraft
js-craft.io › home › javascript includes() multiple values
Javascript includes() multiple values
June 25, 2024 - Ever found yourself needing to check multiple items in a JavaScript array at once? While the includes() function is powerful, it doesn't natively support multiple values. But don't worry!
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.
🌐
Stack Abuse
stackabuse.com › bytes › javascript-check-if-multiple-values-exist-in-array
JavaScript: Check if Multiple Values Exist in Array
September 15, 2023 - The includes() method is a built-in JavaScript method that checks if a specific element exists in an array. It returns true if the element is found, and false otherwise. ... let fruits = ['apple', 'banana', 'cherry', 'date']; console.log(fruits.includes('banana')); // true console.log(frui...
🌐
YouTube
youtube.com › watch
Javascript includes multiple values - YouTube
The Js array includes() function does not have a multiple values search option, but we can simulate this with the help of others array functions.📘 The full ...
Published   December 13, 2023
🌐
gavsblog
gavsblog.com › home › find single or array of values in javascript array using includes
Find single or array of values in JavaScript array using includes - gavsblog
May 23, 2020 - Find out whether a JavaScript array contains single or multiple values by passing an array of values to includes() with the help of some() and every().
🌐
TutorialsPoint
tutorialspoint.com › how-to-check-whether-multiple-values-exist-within-a-javascript-array
How to check whether multiple values exist within a JavaScript array
We are required to write a JavaScript function that takes in two arrays of Numbers and checks whether all the elements of the first array exist in the second or not. Following are our arrays −
Find elsewhere
🌐
Tjvantoll
tjvantoll.com › 2013 › 03 › 14 › better-ways-of-comparing-a-javascript-string-to-multiple-values
Better Ways of Comparing a JavaScript String to Multiple Values
1) You have a string in JavaScript, like var fruit = ''. 2) You need to know if that string is equal to one of multiple values, say "banana" or "lemon" (because the yellow fruits need special yellow fruit processing or something).
🌐
Mimo
mimo.org › glossary › javascript › includes-method
JavaScript includes() method: Syntax, Usage, and Examples
Learn HTML, CSS, JavaScript, and ... functions, objects, and modern ES6+ features ... The includes() method determines whether a string or an array contains a specified value, returning true or false as appropriate....
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-check-if-multiple-values-exist-in-array
Check if Multiple Values exist in Array in JavaScript | bobbyhadz
If even a single value is not contained in the array, the includes() method returns false, which causes the every method to short-circuit also returning false. If you need to do this often, define a reusable function. index.js · Copied!function ...
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript array includes multiple values
JavaScript array includes multiple values
April 20, 2023 - <!DOCTYPE html> <html> <body> <script> const array = [1, 2, 3, 4, 5]; const valuesToCheck = [5, 4]; const hasAllValues = valuesToCheck.every(value => array.includes(value)); console.log(hasAllValues); </script> </body> </html> ... Another way to check if an array contains multiple values in JavaScript.
🌐
Itsourcecode
itsourcecode.com › home › how to check if javascript array includes multiple values?
How to check if JavaScript Array Includes Multiple Values?
July 7, 2023 - As mentioned previously, the includes() ... multiple values includes in an array in JavaScript, you can use the every() method in combination with the includes() method....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › includes
String.prototype.includes() - JavaScript | MDN
const str = "To be, or not to be, that is the question."; console.log(str.includes("To be")); // true console.log(str.includes("question")); // true console.log(str.includes("nonexistent")); // false console.log(str.includes("To be", 1)); // false console.log(str.includes("TO BE")); // false console.log(str.includes("")); // true
🌐
TechOnTheNet
techonthenet.com › js › string_includes.php
JavaScript: String includes() method
This JavaScript tutorial explains how to use the string method called includes() with syntax and examples. In JavaScript, includes() is a string method that determines whether a substring is found in a string.
🌐
Medium
medium.com › @onlinemsr › javascript-includes-the-top-10-things-you-need-to-know-3e59d88b9d09
JavaScript Includes(): The Top 10 Things You Need to Know | by Raja MSR | Medium
July 2, 2023 - The includes() function in JavaScript is used to check whether a given value or element exists within an array or a string.
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › array includes any or all values
Check if a JavaScript array includes any or all values in another array - 30 seconds of code
January 13, 2024 - Checking if an array includes a specific value is pretty straightforward, except when it comes to objects. ... Use the Array.prototype.every() method to check if all values of an array are equal in JavaScript.
🌐
SheCodes
shecodes.io › athena › 220596-how-to-use-the-includes-method-in-javascript
[JavaScript] - How to use the .includes() method in | SheCodes
Learn how to use the `.includes()` method in JavaScript to check if a specific string or element is present in another string or array.