JavaScript String endsWith()
Examples
Check if a string ends with "world":
let text = "Hello world";
let result = text.endsWith("world");
Try it Yourself »
let text = "Hello World";
let result = text.endsWith("world");
Try it Yourself »
More examples below.
Description
The endsWith()
method returns true
if a string ends with a specified string.
Otherwise it returns false
.
The endsWith()
method is case sensitive.
See Also:
Syntax
string.endsWith(searchvalue, length)
Parameters
Parameter | Description |
searchvalue | Required. The string to search for. |
length | Optional. The length of the string to search. Default value is the length of the string. |
Return Value
Type | Description |
A boolean | true if the string ends with the value,
otherwise false . |
More Examples
Check if the 11 first characters of a string ends with "world":
let text = "Hello world, welcome to the universe.";
text.endsWith("world", 11);
Try it Yourself »
Browser Support
endsWith()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
endsWith()
is not supported in Internet Explorer.