JavaScript (ES2026) reference · String Methods
JavaScript String startsWith() Method
Return true if the string begins with the given text. Case-sensitive; an optional position starts the check later.
JavaScript (ES2026) Since ES2015
Syntax
string.startsWith(searchString, position)
Parameters
| Parameter | Description |
|---|---|
searchString |
Text to look for. |
position optional |
Index to check from. Default: 0 |
Return value
true or false.
Examples
const url = "https://www.readycamel.com";
console.log(url.startsWith("https://"), url.startsWith("http://"));
Output
true false
console.log("ReadyCamel".startsWith("Camel", 5));
Output
true
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
str.startswith()· Pythonstr_starts_with()· PHP
Related
string.endsWith()· Return true if the string ends with the given text. Case-sensitive; an optional length treats the string as shorter.string.includes()· Return true if the string contains the given text anywhere. Case-sensitive.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial