JavaScript String startsWith() method

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:

endsWith() method

Instance

Example 1

Starting from position 0:

let text = "Hello world, welcome to the universe.";
text.startsWith("Hello");

Try it yourself

Example 2

Starting from position 6:

let text = "Hello world, welcome to the universe.";
text.startsWith("world", 7);

Try it yourself

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 true.

otherwise return false.

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().

Related Pages

JavaScript String

JavaScript String Methods

JavaScript String Search