JavaScript String includes() method

Definition and usage

If the string contains the specified string,includes() The method will return true.

Otherwise return false.

includes() The method is case-sensitive.

Instance

Example 1

Check if the string contains "world":

let text = "Hello world, welcome to the universe.";
let result = text.includes("world");

Try it yourself

let text = "Hello World, welcome to the universe.";
let result = text.includes("world", 12);

Try it yourself

Example 2

Starting from position 12:

let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);

Try it yourself

Syntax

string.includes(searchvalue, start)

Parameters

Parameters Description
searchvalue Required. The string to be searched.
start Optional. The starting position. The default value is 0.

Return value

Type Description
Boolean value If the string contains this value, then true, otherwise is false.

Browser support

includes() Is ECMAScript6 (ES6) feature.

All modern browsers support ES6 (JavaScript 2015):

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported Supported Supported Supported Supported

Internet Explorer 11 (or earlier versions) is not supported includes().

Related Pages

JavaScript String

JavaScript String Methods

JavaScript String Search