目录

JavaScript String startsWith()

Examples

Start at position 0 (true):

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

Start at position 1 (false):

let text = "Hello world, welcome to the universe.";
text.startsWith("Hello", 1);
Try it Yourself »

Description

The startsWith() method returns true if a string starts with a specified string.

Otherwise it returns false.

The startsWith() method is case sensitive.


Syntax

string.startsWith( searchValue, start)

Parameters

Parameter Description
searchValue Required.
The string to search for.
start Optional.
Start position. Default is 0.

Return Value

Type Description
A boolean Returns true if the string starts with the value.
Otherwise it returns false.



Browser Support

startsWith() is an ECMAScript6 (ES6) feature.

ES6 (JavaScript 2015) is supported in all modern browsers:

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

startsWith() is not supported in Internet Explorer 11 (or earlier).