In JavaScript, the includes() method is used to check the presence of a substring. It determines whether a string contains the given substring or not. The includes() method was introduced in E6/ES2015.

This method returns true if the string contains the given characters, otherwise, it returns false.

The includes() method is case-sensitive, which means it acts differently to both uppercase and lowercase characters.


str.includes(searchString[, position])


The includes() method takes two arguments:

  • searchString — The substring to search for within this string.
  • position — The index to start the search from. This parameter is optional. If not specified, the search will start from zero.

Return value

A Boolean value true indicating the presence of the given substring or false indicating the absence.


Here is a simple example that uses the includes() method to check if a word is present in a sentence:

const sentence = 'The JavaScript is a client-side language.';

const word = 'language';

console.log(`The word "${word}" is ${sentence.includes(word) ? 'present' : 'not present'}.`);
// The word is present.

Since the includes() method is case-sensitive, the following expression will return false:

'JavaScript Jobs'.includes('jobs'); // false

In the above examples, we do not pass the second parameter as we want the search to begin from the start of the string. In most of the use-cases, the second parameter is not required.

However, you can use the second parameter to limit the scope of the search. Here is an example that starts the search from mid of the string saving some precious microseconds:

const str = 'How are you doing? I am much better.';

str.includes('much', 20); // true

If the start index is greater than or equal to the length of the string, the includes() method does not perform any search and simply returns false:

'My name is Atta!'.includes('Atta', 20); // false

If the starting index is less than 0, the includes() method searches the entire string which is same as if no index is specified:

const str = 'Welcome to my blog!';

str.includes('blog', -5); // true


The includes() method is supported by all modern browsers except Internet Explorer and some legacy Android browsers. However, you can easily add the following polyfill to use it on all browsers:

if (!String.prototype.includes) {
  String.prototype.includes = function(search, start) {
    'use strict';
    if (typeof start !== 'number') {
      start = 0;

    if (start + search.length > this.length) {
      return false;
    } else {
      return this.indexOf(search, start) !== -1;

Notice the first line. It feature-detects the support for includes() and only loads the polyfill if the browser does not support the includes() method.

Read Next: Check if a string contains a substring in JavaScript to learn about other JavaScript functions that can be used to check the presence of a substring in a string.

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.