Standard built-ins

String.prototype.endsWith()

Try the free JavaScript compiler

Tests a literal suffix before the given end boundary, or the entire length if omitted.

Formal Syntax & Structure

javascript syntaxjavascript
text.endsWith(searchString, [endPosition])

Parameters & Attributes

NameTypeDescription
searchStringStringLiteral sequence to locate.
endPositionNumberEnd boundary of the checked prefix.

Return Value

Boolean

Whether the suffix matches.

Working Example

Example Snippetjavascript
console.log("a.txt".endsWith(".txt"));
JavaScript Reference