str.startsWith(searchString)
determines whether str
begins with searchString
.
the 1st parameter, the string to search for
- can be just a character
- can be a string
- can contain unicode characters
- a regular expression throws a TypeError
the 2nd parameter, the position where to start searching from
- e.g. find "str" at position 4
- for
undefined
is the same as 0 - the parameter gets converted to an int
- a value larger than the string`s length, returns false
this functionality can be used on non-strings too
- e.g. a boolean
- e.g. a number
- also using the position works
Links
The official specification, actually quite good to read for this function.
The Mozilla Developer Network docs, contains good examples.