Introduced in JavaScript 1.8.6
Determines whether a string begins with the characters of another string, returning true or false as appropriate.
| Method of String | |
|---|---|
| Implemented in | JavaScript 1.8.6 |
| ECMAScript Edition | None (Harmony Proposal) |
Syntax
var startsWith = str.startsWith(searchString [, position]);
Parameters
-
searchString - The characters to be searched for at the start of this string.
-
position -
The position in this string at which to begin searching for
searchString; defaults to 0.
Description
This method lets you determine whether or not a string begins with another string.
Examples
var str = "To be, or not to be, that is the question.";
print(str.startsWith("To be")); // true
print(str.startsWith("not to be")); // false
print(str.startsWith("not to be", 10)); // true
Mozilla Developer Network