字符串的新方法 - endsWith()
endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
str.endsWith(searchString[, length])
参数
searchString- 要搜索的子字符串。
length- 可选。作为
str的长度。默认值为str.length。
var str = "To be, or not to be, that is the question.";
var str2 = 'abc defg'
var str3 = 'and dsh hsh shs'
console.log(str.endsWith("question.")); // true
console.log(str.endsWith("to be")); // false
console.log(str2.endsWith("de", 6)) // true
console.log('abc de'.length) // 6
console.log(str3.endsWith("hs", 10)) // true
console.log('and dsh hs'.length) // 10
浙公网安备 33010602011771号