JavaScript includes()Method

String 对象参考手册JavaScript String Object

Example

Check whether a string contains "Example":

var str = "Hello world, welcome to the Example。"; var n = str.includes("Example");

nOutput:

true

Try it Yourself »

Definition and Usage

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

It returns true if a matching string is found, otherwise it returns false.

Note:The includes() method is case-sensitive.


Browser Support

Method
includes() 41 12.0 40 9 28

Syntax

string.includes(searchvalue, start)

Parameter Values

Parameter Description
searchvalue Required. The string to search for.
start Optional. Sets the position from which to start the search. Default is 0.

Return Value

Type Description
Boolean Returns true if a matching string is found, otherwise returns false.

Technical Details

JavaScript Version: ECMAScript 6


More Examples

Example

Start searching the string from the 12th index position:

var str = "Hello world, welcome to the Example."; var n = str.includes("world", 12);

nOutput:

false

Try it Yourself »

String 对象参考手册JavaScript String Object

Other Extensions