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 since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
includes()
is not supported in Internet Explorer.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.