endsWith(str: String, refStr: String);
str. Base string.
refStr. Substring.
The endsWith method determines whether the string ends with the specified substring.
This method returns True if the string ends with the specified substring, otherwise it returns False.
To execute the example, add a link to PP.js scenario file to HTML page. Determine substrings at the beginning and at the end of the "Text example" base string:
// Set base string var baseStr = "Text example"; // Determine two substrings var subStr1 = "ple"; var subStr2 = "Tex"; // Determine substrings at the beginning and at the end of the base string var isStarts = PP.startsWith(baseStr, subStr2) ? "starts" : "does not start"; console.log("The string «" + baseStr + "» " + isStarts + " with the substring «" + subStr2 + "»."); var isEnds = PP.endsWith(baseStr, subStr1) ? "ends" : "does not end"; console.log("The string «" + baseStr + "» " + isEnds + " with the substring «" + subStr1 + "».");
After executing the example the browser console displays information on the substrings at the beginning and at the end of the "Text example" base string:
The "Text example" string starts with Tex.
The "Text example" string ends with ple.
See also: