There's nothing built-in that will do that for you, you'll have to write a function for it, although it can be just a callback to the some array method.

Two approaches for you:

  • Array some method
  • Regular expression

Array some

The array some method (added in ES5) makes this quite straightforward:

if (substrings.some(function(v) { return str.indexOf(v) >= 0; })) {
    // There's at least one
}

Even better with an arrow function and the newish includes method (both ES2015+):

if (substrings.some(v => str.includes(v))) {
    // There's at least one
}

Live Example:

const substrings = ["one", "two", "three"];
let str;

// Setup
console.log(`Substrings: ${substrings}`);

// Try it where we expect a match
str = "this has one";
if (substrings.some(v => str.includes(v))) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

// Try it where we DON'T expect a match
str = "this doesn't have any";
if (substrings.some(v => str.includes(v))) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

Regular expression

If you know the strings don't contain any of the characters that are special in regular expressions, then you can cheat a bit, like this:

if (new RegExp(substrings.join("|")).test(string)) {
    // At least one match
}

...which creates a regular expression that's a series of alternations for the substrings you're looking for (e.g., one|two) and tests to see if there are matches for any of them, but if any of the substrings contains any characters that are special in regexes (*, [, etc.), you'd have to escape them first and you're better off just doing the boring loop instead. For info about escaping them, see this question's answers.

Live Example:

const substrings = ["one", "two", "three"];
let str;

// Setup
console.log(`Substrings: ${substrings}`);

// Try it where we expect a match
str = "this has one";
if (new RegExp(substrings.join("|")).test(str)) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

// Try it where we DON'T expect a match
str = "this doesn't have any";
if (new RegExp(substrings.join("|")).test(str)) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

Answer from T.J. Crowder 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.
🌐
W3Schools
w3schools.com › jsref › jsref_includes_array.asp
JavaScript Array includes() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
Discussions

Is there a reason Array.includes has restrictive typing?
I think the best issue for explaining what the issue with this is https://github.com/microsoft/TypeScript/issues/31018 That gives some examples of where valid code would produce incorrect runtime types. There's also more details on a potential change to the type system here: https://github.com/microsoft/TypeScript/issues/14520 More on reddit.com
🌐 r/typescript
29
16
August 16, 2024
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
Check if an array contains any element of another array in JavaScript - Stack Overflow
0 how to compare array to see if it contains specific values · 0 Javascript includes() in list of list not working More on stackoverflow.com
🌐 stackoverflow.com
How do I check if an array includes a value in JavaScript? - Stack Overflow
What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) { for (var i = 0; i More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 16
493

There's nothing built-in that will do that for you, you'll have to write a function for it, although it can be just a callback to the some array method.

Two approaches for you:

  • Array some method
  • Regular expression

Array some

The array some method (added in ES5) makes this quite straightforward:

if (substrings.some(function(v) { return str.indexOf(v) >= 0; })) {
    // There's at least one
}

Even better with an arrow function and the newish includes method (both ES2015+):

if (substrings.some(v => str.includes(v))) {
    // There's at least one
}

Live Example:

const substrings = ["one", "two", "three"];
let str;

// Setup
console.log(`Substrings: ${substrings}`);

// Try it where we expect a match
str = "this has one";
if (substrings.some(v => str.includes(v))) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

// Try it where we DON'T expect a match
str = "this doesn't have any";
if (substrings.some(v => str.includes(v))) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

Regular expression

If you know the strings don't contain any of the characters that are special in regular expressions, then you can cheat a bit, like this:

if (new RegExp(substrings.join("|")).test(string)) {
    // At least one match
}

...which creates a regular expression that's a series of alternations for the substrings you're looking for (e.g., one|two) and tests to see if there are matches for any of them, but if any of the substrings contains any characters that are special in regexes (*, [, etc.), you'd have to escape them first and you're better off just doing the boring loop instead. For info about escaping them, see this question's answers.

Live Example:

const substrings = ["one", "two", "three"];
let str;

// Setup
console.log(`Substrings: ${substrings}`);

// Try it where we expect a match
str = "this has one";
if (new RegExp(substrings.join("|")).test(str)) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

// Try it where we DON'T expect a match
str = "this doesn't have any";
if (new RegExp(substrings.join("|")).test(str)) {
    console.log(`Match using "${str}"`);
} else {
    console.log(`No match using "${str}"`);
}

2 of 16
138

One line solution

substringsArray.some(substring=>yourBigString.includes(substring))

Returns true/false if substring exists/doesn't exist

Needs ES6 support

🌐
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....
🌐
Codedamn
codedamn.com › news › javascript
JavaScript includes method for String and Array with Examples
June 2, 2023 - The includes() method is a built-in JavaScript function that checks if a specific element or substring is present in an array or a string, respectively.
🌐
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.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i check if an array includes a value in javascript?
How do I check if an array includes a value in JavaScript? | Sentry
There are two JavaScript array methods that are commonly used to find a value in an array: includes() and indexOf(). If you are checking if an array contains a primitive value, such as a string or number, the solution is more straightforward ...
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Why includes() works with a string? - JavaScript - The freeCodeCamp Forum
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…
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-includes-method
JavaScript Array includes() Method - GeeksforGeeks
javascript · // Taking input as an array A // having some elements. let A = [1, 2, 3, 4, 5]; // includes() method is called to // test whether the searching element // is present in given array or not. a = A.includes(2) // Printing result of ...
Published   January 16, 2026
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
🌐
W3Schools
w3schools.com › jsref › jsref_includes.asp
JavaScript String includes() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
freeCodeCamp
freecodecamp.org › news › check-if-an-item-is-in-an-array-in-javascript-js-contains-with-array-includes
Check if an Item is in an Array in JavaScript – JS Contains with Array.includes()
June 28, 2022 - You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
2 weeks ago - JavaScript arrays are not associative arrays and so, array elements cannot be accessed using arbitrary strings as indexes, but must be accessed using nonnegative integers (or their respective string form) as indexes.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › check-an-array-of-strings-contains-a-substring-in-javascript
Check If An Array of Strings Contains a Substring in JavaScript - GeeksforGeeks
1 week ago - For each string, it checks if 'eks' is included using includes(). If it is, the string is pushed into the accumulator array (acc).
🌐
ReqBin
reqbin.com › code › javascript › vt6ttbek › javascript-array-contains-example
How do I check if an array contains an element in JavaScript?
March 24, 2023 - There are several ways in JavaScript to check if an element exists in an array: The includes() method: the includes() method returns a boolean indicating whether the element is present in the array;
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
Afterwards whenever you need to do something with an array, and you don’t know how – come here, look at the cheat sheet and find the right method. Examples will help you to write it correctly. Soon you’ll automatically remember the methods, without specific efforts from your side. ... Write the function camelize(str) that changes dash-separated words like “my-short-string” into camel-cased “myShortString”.
🌐
Flexiple
flexiple.com › javascript › javascript-array-includes
JavaScript Array includes() Method - Flexiple
April 25, 2024 - The JavaScript Array includes() method checks whether an array contains a specified element, returning true if it does and false otherwise.