目录

JavaScript String includes()

Examples

Check if a string includes "world":

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

More examples below.


Description

The includes() method returns true if a string contains a specified string.

Otherwise it returns false.

The includes() method is case sensitive.


Syntax

string.includes( searchvalue, start)

Parameters

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

Return Value

Type Description
A boolean. true if the string contains the value, otherwise false.


More Examples

Start at position 12:

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

Browser Support

includes() is an ECMAScript6 (ES6) feature.

ES6 (JavaScript 2015) is supported in all modern browsers:

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

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