instance method String#endsWith

View source on GitHub →

String#endsWith(substring[, position]) → Boolean
  • substring (String): The characters to be searched for at the end of this string.
  • [position] (Number): Search within this string as if this string were only this long; defaults to this string's actual length, clamped within the range established by this string's length.

Checks if the string ends with substring.

String#endsWith acts as an ECMAScript 6 polyfill. It is only defined if not already present in the user's browser, and it is meant to behave like the native version as much as possible. Consult the ES6 specification for more information.

Example
'slaughter'.endsWith('laughter')
// -> true
'slaughter'.endsWith('laugh', 6)
// -> true