English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
string.startsWith(searchValue, position)
var str = 'www.oldtoolbag.com'; str.startsWith('W.n') // trueTest and see‹/›
The numbers in the table specify the first browser version that fully supports the startsWith() method:
Method | |||||
startsWith() | 41 | 17 | 28 | 9 | 12 |
Parameters | Description |
---|---|
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 |
Return value: | If the given character is found at the beginning of the stringtrue;otherwisefalse. |
---|---|
JavaScript version: | ECMAScript 6 |
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‹/›