Share via


String.endsWith Function

Determines whether the end of a String object matches a specified string.

var hasSuffixVar = myString.endsWith(suffix);

Arguments

  • suffix
    The string to match with the end of the String object.

Return Value

true if the end of the String object matches suffix; otherwise, false.

Remarks

Use the endsWith function to determine whether the end of the String object matches a specified string. The endsWith function is case sensitive.

Example

The following example shows how to use the endsWith function to determine whether the end of a string matches a specified string. The code excludes non-white-space characters at the end of the string from the validation by invoking the String.trimEnd function. Next it calls the String.toLowerCase function so that case sensitivity is also excluded from the validation. Finally, it calls the endsWith function invoked to test the end of the string for a match.

See Also

Reference

String.startsWith Function

String Object

Other Resources

Language Reference