Favorites

JavaScript String.prototype.startsWith() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.startsWith()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The startsWith() method checks whether a string begins with given text, returning true or false.

Description

The startsWith() method determines whether a string begins with the characters of another string. It's case-sensitive and is clearer than indexOf(x) === 0.

The optional second argument sets the position to start checking from, which lets you test the text after a known prefix without slicing. An empty search string always returns true, and passing a regular expression throws a TypeError.

To check for several possible prefixes, use some() on an array of them, or a regular expression with the ^ anchor, such as /^https?:\/\// to accept both http:// and https://.

Syntax

string.startsWith(searchString)
string.startsWith(searchString, position)

Parameters

  • searchStringThe text to look for at the start.
  • positionOptional. The index to treat as the start.

Return Value

true if the string starts with the search text, otherwise false.

Example

const url = 'https://www.cssportal.com';
console.log(url.startsWith('https://'));
console.log(url.startsWith('www', 8));

Browser Support

The following information will show you the current browser support for the String.prototype.startsWith() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee