THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript String includes() Method

JavaScript String Reference JavaScript String Reference

Example

Check if a string includes with "world":

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

The result of n will be:

true
Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The includes() method determines whether a string contains the characters of a specified string.

This method returns true if the string contains the characters, and false if not.

Note: The includes() method is case sensitive.


Browser Support

Method
includes() 41 12.0 No 40 9 28

Note: The includes() method is not supported in Internet Explorer 11 and earlier versions.


Syntax

string.includes(searchvalue,start)

Parameter Values

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

Technical Details

Return Value: A Boolean. Returns true if the string contains the value, otherwise it returns false
JavaScript Version: ECMAScript 6

Examples

More Examples

Check if a string includes "world", starting the search at position 12:

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

The result of n will be:

false
Try it yourself »

JavaScript String Reference JavaScript String Reference