JavaScript or jQuery string ends with utility function

找出字符串是否以特定值结尾的最简单方法是什么?


you could use Regexps, like this:

str.match(/value$/)

which would return true if the string has 'value' at the end of it ($).


从prototypejs窃取:

String.prototype.endsWith = function(pattern) {
    var d = this.length - pattern.length;
    return d >= 0 && this.lastIndexOf(pattern) === d;
};

'slaughter'.endsWith('laughter');
// -> true

常用表达

"Hello world".match(/world$/)
链接地址: http://www.djcxy.com/p/83894.html

上一篇: 从URL制作JavaScript数组

下一篇: JavaScript或jQuery字符串以效用函数结束