what is the easiest way to figure out if a string ends with a certain value?
Stolen from prototypejs:
String.prototype.endsWith = function(pattern) {
var d = this.length - pattern.length;
return d >= 0 && this.lastIndexOf(pattern) === d;
};
'slaughter'.endsWith('laughter');
// -> true
You can do 'hello world'.slice(-5)==='world'
. Works in all browsers. Much faster than regex.