- Instant help with your JavaScript coding problems
endsWith
The endsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
JavaScript:
endsWith(searchString, length)
TypeScript:
endsWith(searchString: string, endPosition?: number): boolean;
Examples:
let str = 'To be, or not to be, that is the question.'

console.log(str.endsWith('question.'))  // true
console.log(str.endsWith('to be'))      // false
console.log(str.endsWith('to be', 19))  // true

Related snippets