The endsWith(string, index) function

The endsWith() method is used to find whether a string ends with the characters of another string, returning true or false as appropriate. It also takes an optional second parameter representing the position in the string that is assumed as the end of the string. Here is an example to demonstrate this:

const str = "Hi, I am a JS Developer";console.log(str.endsWith("JS Developer")); //Output "true"console.log(str.endsWith("JS", 13)); //Output "true"

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.