JavaScript String startsWith() Method
Example
Check if a string starts with "Hello":
let str = "Hello world, welcome to the universe.";
str.startsWith("Hello") // Returns true
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The startsWith() method returns true
if a string begins with a specified string, otherwise false.
The startsWith() method is case sensitive.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
| Chrome 41 | Edge 12 | Firefox 17 | Safari 9 | Opera 28 |
| Mar 2015 | Jul 2015 | Oct 2012 | Oct 2015 | Mar 2015 |
startsWith() is not supported in Internet Explorer.
Syntax
string.startsWith(searchvalue, start)
Parameter Values
| Parameter | Description |
|---|---|
| searchvalue | Required. The string to search for |
| start | Optional. Default 0. At which position to start the search |
Technical Details
| Return Value: | A Boolean. Returns true if the string starts with the value, otherwise it returns false |
|---|---|
| JavaScript Version: | ECMAScript 6 |
More Examples
Check if a string starts with "world", starting the search at position 6:
var str = "Hello world, welcome to the universe.";
str.startsWith("world", 7) // Returns false
Try it Yourself »

