Javascript examples for String:endsWith
The endsWith() method returns true if the string ends with the characters, and false if not.
Parameter | Description |
---|---|
searchvalue | Required. The string to search for |
length | Optional. Specify the length of the string to search. If omitted, the default value is the length of the string |
A Boolean. Returns true if the string ends with the value, otherwise it returns false
The following code shows how to Check if a string ends with another word:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*ww w.j a va 2 s.c o m*/ var str = "Hello world test world"; var n = str.endsWith("world", 11); document.getElementById("demo").innerHTML = n; } </script> </body> </html>