Skip to content

String.endsWith method

String › endsWith

Official

Checks if the string ends with a specific substring.

Signature:

endsWith(searchString: string, endPosition?: number | undefined): boolean

Parameters:

Parameter Type Description
searchString string The substring to check for.
endPosition? number | undefined The position to end checking at.

Returns: booleantrue if the string ends with the substring, false otherwise.

Remarks:

The original version had different argument names. See bug: https://forum.obsidian.md/t/bug-string-endwith-definition/98103.

Example:

console.log('foo'.endsWith('oo')); // true
console.log('foo'.endsWith('fo')); // false
console.log('foo'.endsWith('foo', 2)); // false
console.log('foo'.endsWith('fo', 2)); // true