The issue is in your if statement because includes() returns a boolean based on the string parameter. A better way of doing this would be to use something like:

if(arr.includes("TL") && arr.includes("TM") && arr.includes("TR")) {
  console.log("yes");
}

If you have lots of elements in your array I would suggest something more along the lines of:

var flag = true;
for(i=0; i<arr.length; i++) {
  if(!arr.includes(arr[i])) {
    flag = false;
  }
}
if(flag) {
  console.log("yes");
}
Answer from brian on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
3 weeks ago - 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
The includes() method returns true if an array contains a specified value.
Discussions

JavaScript - include() - A check to see if multiple elements are in an array - Stack Overflow
hope you can help. I've got an empty array in my project which fill up as certain buttons are pressed (using push()). I want to know when a certain set of elements are in the array. In the below c... More on stackoverflow.com
🌐 stackoverflow.com
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
node.js - Javascript's .includes function not working correctly with array of objects - Stack Overflow
I have an array of objects which I'm using the .includes() function. I'm searching this array with an object that is in the array (Objects are identical). However there doesn't appear to be a match... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How do I use .includes() or similar in a Object? - Stack Overflow
Or find a different alternative to the includes() method, that i'm able to use in an object. More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
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.
Find elsewhere
Top answer
1 of 16
419

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
🌐
freeCodeCamp
forum.freecodecamp.org › programming › javascript
Includes vs. In - JavaScript - The freeCodeCamp Forum
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 ...
🌐
Tabnine
tabnine.com › home › how to use the includes() method in javascript
How to Use the includes() Method in JavaScript - Tabnine
July 25, 2024 - The includes() method is part of both the Array and String prototypes. This method accepts a search value as a parameter, and returns true if the value is either contained in the array on which it is called, or if it exists as a substring of ...
🌐
Scaler
scaler.com › home › topics › javascript array includes() method
JavaScript Array includes() Method - Scaler Topics
February 14, 2024 - The Array includes() method in JavaScript is a built-in function used to search for a specific element within an array. Whether it's a number, string, or any other character, includes() performs a case-sensitive search to determine the presence ...
🌐
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. It returns a boolean result based on whether the text is found or not. Returns true if the string contains the specified value.
Published   3 weeks ago
🌐
freeCodeCamp
forum.freecodecamp.org › programming › 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…
🌐
13WHAM
13wham.com › news › local › rochesters-aging-water-system-includes-pipes-more-than-150-years-old
Rochester’s aging water system includes pipes more than 150 years old
According to documents obtained from the City of Rochester’s Bureau of Water, some of the city’s pipes date back to 1873, making them more than 150 years old.
Published   April 9, 2026
🌐
Adler Planetarium
adlerplanetarium.org › home › tickets
Tickets - Adler Planetarium
April 7, 2026 - CityPASS® saves up to 50% on admission to 5 top Chicago attractions, including the Adler Planetarium, Shedd Aquarium, Skydeck Chicago, the Architecture River Tour, and more! Visit the attractions at your own pace, in any order, over a 9-day period.
🌐
The Eclipse Foundation
eclipse.org › downloads › packages
Eclipse IDE 2026-06 R Packages | Eclipse Packages
Tools for developers working with Java and Web applications, including a Java IDE, tools for JavaScript, TypeScript, JavaServer Pages and Faces, Yaml, Markdown, Web Services, JPA and Data Tools, Maven and Gradle, Git, and more.
🌐
TypeScript
typescriptlang.org › tsconfig
TypeScript: TSConfig Reference - Docs on every TSConfig option
Works in tandem with allowJs. When checkJs is enabled then errors are reported in JavaScript files. This is the equivalent of including // @ts-check at the top of all JavaScript files which are included in your project.