startsWith Method (String) (JavaScript)

Returns a value that indicates whether a string or substring starts with another specified string.

Syntax


stringObj.startsWith(str, [, position]);  

Parameters

stringObj
Required. The string object to search against.

str
Required. The search string.

position
Optional. The position of the first character to search against in the string object, starting at 0.

Return Value

If the string beginning at position starts with the search string, the startsWith method returns true; otherwise, it returns false.

Exceptions

If str is a RegExp, a TypeError is thrown.

Remarks

Requirements

Supported in Microsoft Edge (Edge browser). Also supported in Store apps (Microsoft Edge on Windows 10). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.