Javascript does not have a endsWith function so we have to create it manually we use String prototype for create endsWith function.
if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
Then you can use it directly on string values.
var data = "Lorem ipsum dolor sit amet";
data.endsWith('amet'); //true
img src="any url" onerror="changeimage(this)"
function changeimage(id) {
id.src = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGhLzwUieFALJwbatbY8AsGwNKX2jG17_3f3ZTq1dwsGnx3-E0TLXpMaWriKxSXt2Q-JowqVyXAtYCXJ8H5elZJ4-P6eElixO1g8rOE10C3CqzSHufAQ5BbKKuCKjiqwvbiMEK-G7nJkBS/s1600/NoImage.jpg";
}
