美文网首页
ES6中的字符串常用方法

ES6中的字符串常用方法

作者: EasonChan94 | 来源:发表于2019-01-03 13:58 被阅读0次

    includes(字符串中是否包含某个字符,第二个参数表示从第几个字符开始):

    用法:String.includes(str,index)
    返回值:Boolean

    var str = "hello world!"
    console.log(str.includes("hello")); // true
    console.log(str.includes("hello",2)); // false
    

    startsWith(某个字符是否处于该字符串之首,第二个参数表示从第几个字符开始):

    用法:String.startsWith(str,index)
    返回值:Boolean

    var str = "hello world!"
    console.log(str.startsWith("h")); // true
    console.log(str.startsWith("h",2)); // false
    

    endsWith(某个字符是否处于该字符串之尾,第二个参数表示从第几个字符开始):

    用法:String. endsWith(str,index)
    返回值:Boolean

    var str = "hello world!"
    console.log(str.endsWith("!")); // true
    console.log(str.endsWith("!",2)); // false
    console.log(str.endsWith("!",str.length)); // true
    

    相关文章

      网友评论

          本文标题:ES6中的字符串常用方法

          本文链接:https://www.haomeiwen.com/subject/elyfrqtx.html