endsWith (JavaScript)

Checks whether a string ends with a substring.

Defined in

String (Standard - JavaScript)

Syntax

endsWith(str:string) : boolean
Parameters Description
str A substring.
Return value Description
boolean True if this string ends with the substring, or the substring is empty.

Examples

(1) The following comparison is true.
var cities = new String("Paris   Moscow   Tokyo");
if (cities.endsWith("Tokyo"))
	return "Ends with Tokyo";
else
	return "Does not end with Tokyo"
(2) The following comparison is false.
cities = new String("Paris   Moscow   Tokyo");
if (cities.endsWith("TOKYO"))
	return "Ends with TOKYO";
else
	return "Does not end with TOKYO"