endsWith

This article is in need of a technical review.

This article is in need of an editorial review.

  • Tags
  • Files

Introduced in JavaScript 1.8.6

Summary

Determines whether a string ends with the characters of another string, returning true or false as appropriate.

Method of String
Implemented in JavaScript 1.8.6
ECMAScript Edition None (Harmony Proposal)

Syntax

var endsWith = str.endsWith(searchString [, position]);

Parameters

searchString
The characters to be searched for at the end of this string.
position
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.

Description

This method lets you determine whether or not a string ends with another string.

Examples

var str = "To be, or not to be, that is the question.";

print( str.endsWith("question") );  // true
print( str.endsWith("to be") );     // false
print( str.endsWith("to be", 19) ); // true
Contributors to this page: ethertank, Waldo
Last updated by: ethertank,
Last reviewed by: ethertank,