String endsWith()
str.endsWith(search, length)
str
is a stringsearch
is a stringlength
is an integer, and optional
endsWith() method returns true
if the string str
ends with the specified search
string, else it returns false
. If length
is provided, only this length of the string str
is considered for checking.
Examples
1. check if string value in name
ends with search string 'le'
.
let name = 'apple';
let output = name.endsWith('le');
console.log(output);
2. check if string value in name
ends with search string 'nana'
.
let name = 'apple';
let output = name.endsWith('nana');
console.log(output);
3. check if string value in name
ends with search string 'pl'
in the length of 4
.
let name = 'apple';
let output = name.endsWith('pl', 4);
console.log(output);