ES6 - New String Method endsWith


Advertisements

This function determines whether a string ends with the characters of another string.

Syntax

str.endsWith(matchstring[, position])

Parameters

  • matchstring − The characters that the string must end with. It is case sensitive.

  • Position − The position to match the matchstring. This parameter is optional.

Return Value

true if the string ends with the characters of the match string; otherwise, false.

Example

var str = 'Hello World !!! '; 
 
console.log(str.endsWith('Hello')); 
console.log(str.endsWith('Hello',5));

Output

false 
true 
es6_new_string_methods.htm
Advertisements