JavaScript String startsWith()
Examples
Start at position 0:
let text = "Hello world, welcome to the universe.";
text.startsWith("Hello");
Try it Yourself »
Start at position 6:
let text = "Hello world, welcome to the universe.";
text.startsWith("world", 7);
Try it Yourself »
Definition and Usage
The startsWith()
method returns true
if a string starts with a specified string.
Otherwise it returns false
.
The startsWith()
method is case sensitive.
See also the endsWith()
method.
Syntax
string.startsWith(searchValue, start)
Parameters
Parameter | Description |
searchValue | Required. The string to search for. |
start | Optional. Start position. Default is 0. |
Return Value
Type | Description |
A boolean | Returns true if the string starts with the value.Otherwise it returns false . |
Browser Support
startsWith()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
startsWith()
is not supported in Internet Explorer 11 (or earlier).