The endsWith() method determines whether a string ends with a specified string.
The endsWith() method determines whether a string ends with a specified string.
This method returns true if the string ends with the characters, and false if not.
The endsWith() method is case sensitive.
string.endsWith(searchvalue,length)
Parameter | Require | 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
Check if a string ends with "world", assuming the string is 11 characters long:
var str = "Hello world, this is a test."; var n = str.endsWith("world", 11); console.log(n);
Check if a string ends with "universe.":
//check where if the string ends with the specified value. var str = "Hello world, welcome to the universe."; var n = str.endsWith("universe."); console.log(n);/* ww w. j a v a 2 s . c om*/