JavaScript String startsWith() method
- Previous Page split()
- Next Page substr()
- Go to Parent Directory JavaScript String Reference Manual
Definition and usage
if the string starts with the specified string startsWith()
The method returns true
, otherwise return false
.
startsWith()
Methods are case-sensitive.
See also:
Instance
Example 1
Starting from position 0:
let text = "Hello world, welcome to the universe."; text.startsWith("Hello");
Example 2
Starting from position 6:
let text = "Hello world, welcome to the universe."; text.startsWith("world", 7);
Syntax
string.startsWith(searchValue, start)
Parameters
Parameters | Description |
---|---|
searchValue | Required. The string to search for. |
start | Optional. Starting position. Default value is 0. |
Return value
Type | Description |
---|---|
Boolean value |
return if the string starts with this value otherwise return |
Browser support
startsWith()
is an ECMAScript6 (ES6) feature.
All browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
supports | supports | supports | supports | supports |
Internet Explorer 11 (or earlier versions) does not support startsWith()
.
- Previous Page split()
- Next Page substr()
- Go to Parent Directory JavaScript String Reference Manual