English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript String startsWith() Method

 JavaScript String Object

startsWith()The method determines whether the string starts with the specified character of the string.

If the string starts with the character, the startsWith() method returnstrueotherwise returnfalse.

Note:This method is case-sensitive.

Syntax:

string.startsWith(searchValue, position)
var str = 'www.oldtoolbag.com';
str.startsWith('W.n')   // true
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the startsWith() method:

Method
startsWith()411728912

Parameter Value

ParametersDescription
searchValue(Required) The character to search for at the beginning of this string
position(Optional) The starting position to search in this stringthe position of searchValue;default is 0

Technical Details

Return value:If the given character is found at the beginning of the stringtrue;otherwisefalse.
JavaScript version:ECMAScript 6

More examples

Check if the string starts with 'Pollution' from position4Start searching:

var str = 'Air Pollution is the introduction of chemicals to the atmosphere.';
str.startsWith('Pollution', 4);
Test and see‹/›

 JavaScript String Object