JavaScript String endsWith()
Example
Check if a string ends with "universe.":
let str = "Hello world";
str.endsWith("world") // Returns true
str.endsWith("World") // Returns false
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The endsWith() method returns true if a string ends with a specified string,
otherwise false.
endsWith() is case sensitive.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
| Chrome 41 | Edge 12 | Firefox 17 | Safari 9 | Opera 36 |
| Mar 2015 | Jul 2015 | Oct 2012 | Oct 2015 | Mar 2016 |
endsWith() is not supported in Internet Explorer.
Syntax
string.endsWith(searchvalue, length)
Parameter Values
| 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 |
Technical Details
| Return Value: | A Boolean. Returns true if the string ends with the value, otherwise it returns false |
|---|---|
| JavaScript Version: | ECMAScript 6 |
More Examples
Check if a string ends with "world", assuming the string is 11 characters long:
let str = "Hello world, welcome to the universe.";
str.endsWith("world", 11) // Returns true
Try it Yourself »

