Using slice method to check string end - Node.js String

Node.js examples for String:String End

Description

Using slice method to check string end

Demo Code


if (typeof String.prototype.endsWith != 'function') {
  String.prototype.endsWith = function(str) {
    return this.slice(-str.length) == str;
  };//from w ww . j a  va 2s . c  om
}

Related Tutorials