English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
endsWith()The method determines whether a string ends with the specified string.
If the string ends with the specified character, the endsWith() method returnstrue,Otherwise, it returnsfalse
Note:This method is case-sensitive.
The string.endsWith(searchValue, length) method is used.
var str = &39;www.oldtoolbag.com&39;; str.endsWith(&39;com&39;);// trueTest and see‹/›
The numbers in the table specify the first browser version that fully supports the endsWith() method:
Method | |||||
endsWith() | 41 | 17 | 28 | 9 | 12 |
Parameter | Description |
---|---|
searchValue | (Required) The character to be searched at the end of this string |
length | (Optional) Specify the length of the string to be searched. If omitted, the default value is the length of the string |
Return Value: | Returns true if the specified character is found at the end of the string; otherwise, it returns false |
---|---|
JavaScript Version: | ECMAScript 6 |
Specify the length of the string to be searched:
var str = &39;To be, or not to be, that is the question.&39;; str.endsWith(&39;to be&39;, 19); // trueTest and see‹/›