How to find if an array contains a specific String in JavaScript?

Estimated read time 1 min read

You can use the Array.prototype.includes() method to check if an array contains a specific string in JavaScript. Here’s an example:

let arr = ['apple', 'banana', 'cherry'];
let search = 'banana';

if (arr.includes(search)) {
  console.log(`The array contains the string "${search}"`);
} else {
  console.log(`The array does not contain the string "${search}"`);
}

This will output The array contains the string "banana".

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply