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
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › includes
String.prototype.includes() - JavaScript | MDN
The includes() method of String values performs a case-sensitive search to determine whether a given string may be found within this string, returning true or false as appropriate.
Discussions

multiple conditions for JavaScript .includes() method - Stack Overflow
Just wondering, is there a way to add multiple conditions to a .includes method, for example: var value = str.includes("hello", "hi", "howdy"); Imagine the comma states "or". It's asking now ... More on stackoverflow.com
🌐 stackoverflow.com
Why includes() works with a string?
Hello, In MDN doc : " The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate." But If I use a string: let string = 'string' console.log(str… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
February 21, 2022
Difference between String.prototype.includes/contains in ES6? What about .has?
From what I've seen is that both ... why did ES6 use .has when it could've used .contains or .includes to serve multiple purposes under one name. I am aware .has isn't used on strings. ... Check this section in MDN.... More on stackoverflow.com
🌐 stackoverflow.com
“In” vs. “Includes” in JavaScript: Are They the Same?
(Potential copy, got message that my prior comment was removed due to having links): The two are different in that in is used for arrays and objects while includes() is for arrays and strings. Note that while in can be used for arrays, it is recommended to use includes() instead (or .has() if you are using a Set). You can also use in in loops: for (const key in object) {} which will loop over the keys of an object. For arrays it would loop over the indices. If you want more info, I cannot recommend the MDN docs about them enough as they both can have gotchas about using them (as 100% of JS does as the language is a hot mess). More on reddit.com
🌐 r/GetStudying
3
1
April 4, 2025
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Includes vs. In
August 18, 2022 - Today I ran into some trouble with a line of code that seems to be misleading. I tried to use if (!(arr[n][i] in arr[0])){ but I found I had to rewrite the code as if (!(result.includes(arr[n][i]))){ I am having difficulty understanding the difference between the array.includes() function and ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
1 week ago - Note: If you're not yet familiar with array basics, consider first reading JavaScript First Steps: Arrays, which explains what arrays are, and includes other examples of common array operations.
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Node › contains
Node: contains() method - Web APIs | MDN
June 24, 2025 - The contains() method of the Node interface returns a boolean value indicating whether a node is a descendant of a given node, that is the node itself, one of its direct children (childNodes), one of the children's direct children, and so on.
Find elsewhere
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › String › includes
String.prototype.includes() - JavaScript
The includes() method determines whether one string may be found within another string, returning true or false as appropriate. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://gi...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › some
Array.prototype.some() - JavaScript | MDN
1 week ago - Array.prototype.includes() TypedArray.prototype.some() Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Feb 24, 2026 by MDN contributors.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Why includes() works with a string?
February 21, 2022 - Hello, In MDN doc : " The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate." But If I use a string: let string = 'string' console.log(str…
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › TypedArray › includes
TypedArray.prototype.includes() - JavaScript | MDN
July 10, 2025 - The includes() method of TypedArray instances determines whether a typed array includes a certain value among its entries, returning true or false as appropriate. This method has the same algorithm as Array.prototype.includes().
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › IDBKeyRange › includes
IDBKeyRange: includes() method - Web APIs | MDN
March 6, 2024 - The includes() method of the IDBKeyRange interface returns a boolean indicating whether a specified key is inside the key range.
🌐
W3Schools
w3schools.com › jsref › jsref_includes_array.asp
W3Schools.com
The includes() method returns true if an array contains a specified value.
🌐
Stack Overflow
stackoverflow.com › questions › 33050189 › difference-between-string-prototype-includes-contains-in-es6-what-about-has
Difference between String.prototype.includes/contains in ES6? What about .has?
From what I've seen is that both ... why did ES6 use .has when it could've used .contains or .includes to serve multiple purposes under one name. I am aware .has isn't used on strings. ... Check this section in MDN....
🌐
Treehouse Blog
blog.teamtreehouse.com › javascript-array-methods-includes
JavaScript Array Methods: includes() | Treehouse Blog
September 11, 2023 - The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate. MDN – includes() documentation
Top answer
1 of 16
5530

Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE:

console.log(['joe', 'jane', 'mary'].includes('jane')); // true

You can also use Array#indexOf, which is less direct, but doesn't require polyfills for outdated browsers.

console.log(['joe', 'jane', 'mary'].indexOf('jane') >= 0); // true


Many frameworks also offer similar methods:

  • jQuery: $.inArray(value, array, [fromIndex])
  • Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes)
  • Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast])
  • Prototype: array.indexOf(value)
  • MooTools: array.indexOf(value)
  • MochiKit: findValue(array, value)
  • MS Ajax: array.indexOf(value)
  • Ext: Ext.Array.contains(array, value)
  • Lodash: _.includes(array, value, [from]) (is _.contains prior 4.0.0)
  • Ramda: R.includes(value, array)

Notice that some frameworks implement this as a function, while others add the function to the array prototype.

2 of 16
510

Update from 2019: This answer is from 2008 (11 years old!) and is not relevant for modern JS usage. The promised performance improvement was based on a benchmark done in browsers of that time. It might not be relevant to modern JS execution contexts. If you need an easy solution, look for other answers. If you need the best performance, benchmark for yourself in the relevant execution environments.

As others have said, the iteration through the array is probably the best way, but it has been proven that a decreasing while loop is the fastest way to iterate in JavaScript. So you may want to rewrite your code as follows:

function contains(a, obj) {
    var i = a.length;
    while (i--) {
       if (a[i] === obj) {
           return true;
       }
    }
    return false;
}

Of course, you may as well extend Array prototype:

Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}

And now you can simply use the following:

alert([1, 2, 3].contains(2)); // => true
alert([1, 2, 3].contains('2')); // => false
🌐
MDN
mdn2.netlify.app › en-us › docs › web › javascript › reference › global_objects › typedarray › includes
TypedArray.prototype.includes() - JavaScript | MDN
March 27, 2022 - The includes() method determines whether a typed array includes a certain element, returning true or false as appropriate. This method has the same algorithm as Array.prototype.includes(). TypedArray is one of the typed array types here.
🌐
Codedamn
codedamn.com › news › javascript
JavaScript includes method for String and Array with Examples
June 2, 2023 - A: Older browsers might not support the includes() method. As an alternative, you can use the indexOf() method, which returns the index of the first occurrence of the specified value or -1 if the value is not found. For more information and examples, check out the official MDN Web Docs and Array.prototype.includes() documentation.
🌐
EJS
ejs.co
EJS -- Embedded JavaScript templates
Includes are relative to the template with the include call.