endsWith in JavaScript

前端 未结 30 1437
-上瘾入骨i
-上瘾入骨i 2020-11-22 05:41

How can I check if a string ends with a particular character in JavaScript?

Example: I have a string

var str = \"mystring#\";

I wa

30条回答
  •  独厮守ぢ
    2020-11-22 06:07

    all of them are very useful examples. Adding String.prototype.endsWith = function(str) will help us to simply call the method to check if our string ends with it or not, well regexp will also do it.

    I found a better solution than mine. Thanks every one.

提交回复
热议问题