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
Is there a endsWith()
method in JavaScript? JavaScript中是否有endsWith()
方法? code
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? 這是最好的方法仍是還有其餘方法? 字符串