ES6 version of this is (check out answer from Allison):

!str1.includes(str2)

The original accepted answer was:

You are looking for indexOf

var x = "home.subjects.subject.exams.exam.tests";
console.log(x.indexOf('subjects'));     // Prints 5
console.log(x.indexOf('state'));        // Prints -1
Answer from Ananth on Stack Overflow
🌐
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.
🌐
W3Schools
w3schools.com › jsref › jsref_includes.asp
W3Schools.com
The includes() method returns true if a string contains a specified string.
Discussions

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
How to check if a string contains text from an array of substrings in JavaScript? - Stack Overflow
the only answer that returns the matched array string. this should have been included in previous example for completeness sake 2022-01-25T22:57:25.833Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
How to use includes method to see if string is an of array of specific strings?
As it looks like you figured out, you need to either use a type guard function first or generalize the array's type to string[]. This is actually a somewhat annoying deficiency of Typescript, as detailed in this GitHub issue , where includes() can't serve as a type guard itself. I ran into it recently at work, where the argument to includes() was dynamically determined. More on reddit.com
🌐 r/typescript
9
4
December 15, 2021
Formula for Countifs, with string includes text1 or text2
u/farmgirlwi - Your post was submitted successfully. Once your problem is solved, reply to the answer(s) saying Solution Verified to close the thread. Follow the submission rules -- particularly 1 and 2. To fix the body, click edit. To fix your title, delete and re-post. Include your Excel version and all other relevant information Failing to follow these steps may result in your post being removed without warning. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/excel
4
0
October 1, 2023
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase.
🌐
Mimo
mimo.org › glossary › javascript › includes-method
JavaScript includes() method: Syntax, Usage, and Examples
The includes() method in JavaScript checks whether a given value exists in a string or array. This functionality is particularly valuable in modern web development when working with data from HTML elements or applying conditional CSS styles.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-includes-method
JavaScript String includes() Method - GeeksforGeeks
The includes() method is used to check whether a string contains a specific value.
Published   January 16, 2026
Find elsewhere
🌐
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…
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

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.string.contains
String.Contains Method (System) | Microsoft Learn
Dim sub1 As String = "this" Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1) Dim comp As StringComparison = StringComparison.Ordinal Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp)) comp = StringComparison.OrdinalIgnoreCase Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp)) End Sub End Module ' The example displays the following output: ' Does 'This is a string.' contain 'this'? ' Ordinal: False ' OrdinalIgnoreCase: True · If you are interested in the position of the substring value in the current instance, you can call the IndexOf method to get the starting position of its first occurrence, or you can call the LastIndexOf method to get the starting position of its last occurrence. The example includes a call to the IndexOf(String) method if a substring is found in a string instance.
🌐
Hugo
gohugo.io › functions › strings › contains
strings.Contains
April 10, 2025 - Reports whether the given string contains the given substring.
🌐
Can I Use
caniuse.com › es6-string-includes
String.prototype.includes | Can I use... Support tables for HTML5, CSS3, etc
The includes() method determines whether one string may be found within another string, returning true or false as appropriate.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › includes
JavaScript String includes() - Check Substring Presence | Vultr Docs
November 14, 2024 - The includes() method in JavaScript provides a straightforward approach to verify if a string contains a specific substring.
🌐
W3Schools
w3schools.com › java › ref_string_contains.asp
Java String contains() Method
The contains() method checks whether a string contains a sequence of characters.
🌐
Medium
medium.com › nerd-for-tech › basics-of-javascript-string-includes-method-107b6094f00b
Basics of Javascript · String · includes() (method) | by Jakub Korch | Nerd For Tech | Medium
June 4, 2021 - The includes() method performs a case-sensitive search to determine whether a specified string may be found within the searched string. Returning value can either be true or false based on a result of search.
🌐
PTC Community
community.ptc.com › t5 › ThingWorx-Developers › Using-includes-on-a-string-never-works › td-p › 628132
Solved: Using .includes() on a string never works - PTC Community
September 24, 2019 - Whenever I attempt to use the '.includes()' method on string in ThingWorx composer, I always get an error saying that the .includes method can not be found on the object. I even log the type of the variable that I am trying to edit, just to make sure it is in fact a string.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › contains-substring
Check if a String Contains a Substring in JavaScript - Mastering JS
May 16, 2019 - There's two common ways to check whether a string contains a substring in JavaScript. The more modern way is the String#includes() function.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
contains - Determine if pattern is in strings - MATLAB
This MATLAB function returns 1 (true) if str contains the specified pattern, and returns 0 (false) otherwise.
🌐
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.