JavaScript String endsWith() method
- Previous Page constructor
- Next Page fromCharCode()
- Go Up One Level JavaScript String Reference Manual
Definition and usage
If the string ends with the specified string,endsWith()
The method returns true
.
otherwise returns false
.
endsWith()
The method is case-sensitive.
See also:
Example
Example 1
Check if the string ends with "world":
let text = "Hello world"; let result = text.endsWith("world");
let text = "Hello World"; let result = text.endsWith("world");
Example 2
Check if the first 11 characters of the string end with "world":
let text = "Hello world, welcome to the universe."; text.endsWith("world", 11);
Syntax
string.endsWith(searchvalue, length)
Parameter
Parameter | Description |
---|---|
searchvalue | Required. The string to search for. |
length |
Optional. The length of the string to search for. The default value is the length of the string. |
Return value
Type | Description |
---|---|
Boolean value | If the string ends with this value, true otherwise, false . |
Browser support
endsWith()
It is an ECMAScript6 (ES6) feature.
All browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supported | Supported | Supported | Supported | Supported |
Internet Explorer 11 (and earlier versions) does not support endsWith().
- Previous Page constructor
- Next Page fromCharCode()
- Go Up One Level JavaScript String Reference Manual