what is the easiest way to figure out if a string ends with a certain value?
The endsWith() method determines whether a string ends with the characters of another string, returning true or false as appropriate. This method is case-sensitive.
jQuery is an object provided by jQuery. $ is another, which is just an alias to jQuery . $$ is not provided by jQuery. It's provided by other libraries, such as Mootools or Prototype. js.
you could use Regexps, like this:
str.match(/value$/)
which would return true if the string has 'value' at the end of it ($).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With