JavaScript中的endsWith - endsWith in JavaScript

問題:

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

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

var str = "mystring#";

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

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

  2. One solution I have is take the length of the string and get the last character and check it. 我有一個解決方案是獲取字符串的長度並獲取最後一個字符並進行檢查。 ip

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
相關文章
相關標籤/搜索