JSFiddle - React, Tailwind, and code Playground
JavaScript
function end(str, target) {
return target.length > 0 && target === str.substr(str.length - target.length);
}
alert(end('Bastian', 'an')); // true
alert(end('Bastian', 'tia')); // false
alert(end('Bastian', 'tian')); // true
alert(end('Bastian', '')); // false
alert(end('Bastian', '123')); // false