startsWith (JavaScript)

Checks whether a string starts with a substring.

Defined in

String (Standard - JavaScript)

Syntax

startsWith(str:string) : boolean
Parameters Description
str The substring.
Return value Description
boolean True if this string starts with the substring, or the substring is empty.

Examples

(1) The following comparison is true.
var cities = new String("Paris   Moscow   Tokyo");
if (cities.startsWith("Paris"))
	return "Starts with Paris";
else
	return "Does not start with Paris"
(2) The following comparison is false.
var cities = new String("Paris   Moscow   Tokyo");
if (cities.startsWith("paris"))
	return "Starts with Paris";
else
	return "Does not start with Paris"