JavaScript String includes() method
- Previous Page fromCharCode()
- Next Page indexOf()
- Go to the Previous Level JavaScript String Reference Manual
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");
let text = "Hello World, welcome to the universe."; let result = text.includes("world", 12);
Example 2
Starting from position 12:
let text = "Hello world, welcome to the universe."; let result = text.includes("world", 12);
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()
.
- Previous Page fromCharCode()
- Next Page indexOf()
- Go to the Previous Level JavaScript String Reference Manual