JavaScript or jQuery string ends with utility function

后端 未结 8 1862
遥遥无期
遥遥无期 2020-12-23 23:56

what is the easiest way to figure out if a string ends with a certain value?

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 00:50

    You can always prototype String class, this will work:

    String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)}

    You can find other related extensions for String class in http://www.tek-tips.com/faqs.cfm?fid=6620

提交回复
热议问题