JavaScript String startsWith()
Examples
Start at position 0 (true):
let text = "Hello world, welcome to the universe.";
text.startsWith("Hello");
Try it Yourself »
Start at position 1 (false):
let text = "Hello world, welcome to the universe.";
text.startsWith("Hello", 1);
Try it Yourself »
Description
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:
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 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |