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 booleanReturns 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 since June 2017:

Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 Apr 2017 Jun 2017 Sep 2016 Jun 2016

startsWith() is not supported in Internet Explorer.


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.