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 »
The startsWith()
method returns true
if a string starts with a specified string.
Otherwise it returns false
.
The startsWith()
method is case sensitive.
string.startsWith(
searchValue,
start)
Parameter | Description |
searchValue | Required. The string to search for. |
start | Optional. Start position. Default is 0. |
Type | Description |
A boolean | Returns true if the string starts with the value.Otherwise it returns false . |
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).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!