JavaScript String startsWith() method

Definition and usage

If the string starts with the specified string, then startsWith() Method returns true, otherwise return false.

startsWith() Method is 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)

Parameter

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

Return value

Type Description
Boolean value

If the string starts with this value, return true.

ka tsa false.

Browser support

startsWith() ni ECMAScript6 (ES6) ce gurɗe.

All browsers support ES6 (JavaScript 2015):

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
tana ce tsa tana ce tsa tana ce tsa tana ce tsa tana ce tsa

Internet Explorer 11 (tana ce tsa) ko ba kai ce tsa startsWith().

Ɗanararar

JavaScript ɗanararar

JavaScript ɗanararar ɗanararar

JavaScript ɗanararar ɗanararar