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.
The includes()
method returns true
if a string contains a specified string.
Otherwise it returns false
.
The includes()
method is case sensitive.
string.includes(
searchvalue,
start)
Parameter | Description |
searchvalue | Required. The string to search for. |
start | Optional. The position to start from. Default value is 0. |
Type | Description |
A boolean. | true if the string contains the value, otherwise false . |
Start at position 12:
let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);
Try it Yourself »
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).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!