endsWith()
ES6+Determines whether a string ends with the characters of a specified string.
Syntax
string.endsWith(searchString, length)Parameters
searchString string The characters to search for at the end
length number optionalLength of string to search within
Return Value
boolean
true if the string ends with the given characters
Examples
JavaScript
const str = 'Hello World';
console.log(str.endsWith('World'));
console.log(str.endsWith('Hello')); Output:
// true
false