Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript includes() Method

JavaScript includes() Method

String Object Reference JavaScript String object

Example

Check whether a string contains "Runoob":

var

str

=

"

Hello world, welcome to the Runoob.

"

;

var

n

=

str

.

includes

(

"

Runoob

"

)

;

n Output result:

true

Try it »


Definition and Usage

The includes() method is used to determine whether a string contains a specified substring.

If a matching string is found, it returns true; otherwise false.

Note: The includes() method is case sensitive.


Browser support

Method
includes() 41 12.0 40 9 28

Syntax


string.includes(searchvalue, start)

Parameter value

Parameters Description
searchvalue Required, the string to search for.
start Optional, sets the position from which to start searching, defaulting to 0.

Return Value

Type Description
Boolean If a matching string is found, it returns true; otherwise false.

Technical Details

JavaScript version: ECMAScript 6

More examples

Example

Start searching for the string from index position 12:

var

str

=

"

Hello world, welcome to the Runoob.

"

;

var

n

=

str

.

includes

(

"

world

"

,

12

)

;

n Output result:

false

Try it »


String Object Reference JavaScript String object