JavaScript中的endsWith 4年前

编程语言
714
JavaScript中的endsWith

问题:

How can I check if a string ends with a particular character in JavaScript? 如何在JavaScript中检查字符串是否以特定字符结尾?

Example: I have a string 示例:我有一个字符串

var str = "mystring#";

I want to know if that string is ending with # . 我想知道该字符串是否以#结尾。 How can I check it? 我该如何检查?

  1. Is there a endsWith() method in JavaScript? JavaScript中是否有endsWith()方法?

  2. One solution I have is take the length of the string and get the last character and check it. 我有一个解决方案是获取字符串的长度并获取最后一个字符并进行检查。

Is this the best way or there is any other way? 这是最好的方法还是还有其他方法?


解决方案:

参考一: https://stackoom.com/question/1B0M/JavaScript中的endsWith
参考二: https://oldbug.net/q/1B0M/endsWith-in-JavaScript

Y
YOUMEI
生在此侧,死在彼侧。我在此侧,不在彼侧。
3
发布数
2
关注者
1638
累计阅读

热门教程文档

React
18小节
MySQL
34小节
Golang
23小节
Spring Cloud
8小节
Next
43小节
广告