endsWith in JavaScript

前端 未结 30 1434
-上瘾入骨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:17

    I just learned about this string library:

    http://stringjs.com/

    Include the js file and then use the S variable like this:

    S('hi there').endsWith('hi there')
    

    It can also be used in NodeJS by installing it:

    npm install string
    

    Then requiring it as the S variable:

    var S = require('string');
    

    The web page also has links to alternate string libraries, if this one doesn't take your fancy.

提交回复
热议问题