JavaScript String endsWith() Method

You are Here:

JavaScript String endsWith() Method

The endsWith() method returns a Boolean value indicates whether a string ends with the characters of a specified string.

Note: The endsWith() method is case sensitive.

endsWith() with searchValue

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var str = "Hello there my old friend"; var result = str.endsWith("end"); document.write(result); </script> </body> </html>

Syntax

str.endsWith(searchValue, length)

Parameter Values

ValueTypeExplanation
searchValueRequiredSpecifies the characters to be searched for at the end of this string.
lengthoptionalSpecifies length or limit of string to search.
If omitted, the default value is the length of the string.

Return Values

ValueExplanation
trueIf the given characters are found at the end of the string
falseIf the given characters are not found at the end of the string

endsWith() with searchValue and length

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var str = "Hello there my old friend"; var result = str.endsWith("old", 18); document.write(result); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author