English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript String endsWith() Method

 JavaScript String Object

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.

Syntax:

The string.endsWith(searchValue, length) method is used.
var str = &39;www.oldtoolbag.com&39;;
str.endsWith(&39;com&39;);// true
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the endsWith() method:

Method
endsWith()411728912

Parameter Value

ParameterDescription
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

Technical Details

Return Value:Returns true if the specified character is found at the end of the string; otherwise, it returns false
JavaScript Version:ECMAScript 6

More Examples

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);   // true
Test and see‹/›

 JavaScript String Object