ES6 - String.prototype.endsWith()



This function determines whether a string ends with the characters of a specified string and returns true or false.

Syntax

The syntax which is mentioned below is for String.prototype.endsWith(), where, searchString is the characters to be searched for at the end of this string. length is an optional parameter. It represents the length of string.

str.endsWith(searchString[, length])

Example

<script>
   let company = 'TutorialsPoint'
   console.log(company.endsWith('Point'));
   console.log(company.endsWith('Tutor',5))//5 is length of string
</script>

The output of the above code will be as mentioned below −

true
true
Advertisements