字符串的新方法 - 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

  

 

posted @ 2020-03-23 20:31  banzhuxiang  阅读(233)  评论(0)    收藏  举报