ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

endsWith

adds endsWith method to the prototype of String. Returns boolean

Source

String.prototype.endsWith = function(suffix) {
    return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

Example

console.log("hi this ends with a dollar".endsWith('dollar')); //true

Author: Amit Joki

Submitted on: 9 mei 2014

Language: JavaScript

Type: endsWith

Views: 5152