美文网首页
字符串的拓展

字符串的拓展

作者: Home_2453 | 来源:发表于2019-03-06 11:32 被阅读0次

1、includes() 返回布尔值,表示是否找到了参数字符串。

let s = 'hello world';
console.log(s.includes('o'));    //true

2、startsWith() 返回布尔值,表示参数字符串是否在原字符串的头部。

let s = 'hello world';
console.log(s.startsWith('hello'));    //true
console.log(s.startsWith('h'));    //true
console.log(s.startsWith('e'));    //false

3、endsWith() 返回布尔值,表示参数字符串是否在原字符串的尾部。

let s = 'hello world';
console.log(s.endsWith('hello'));    //false
console.log(s.endsWith('h'));    //false
console.log(s.endsWith('d'));    //true

4、repeat() 方法返回一个新字符串,表示将原字符串重复n次。

let a = 'repeat';
console.log(a.repeat(10));  //repeatrepeatrepeatrepeatrepeatrepeatrepeatrepeatrepeatrepeat

5、模板字符串
模板字符串是增强版字符串,用反引号(`)标识。它可以当作普通字符串使用,也可以用来定义多行字符串,或者在字符串中嵌入变量。
模板字符串嵌入变量,需要将变量写进${}之中。
模板字符串中还能调用函数。

 function a (){
        return 10
    }
 console.log(`${a()}`)    //10

相关文章

  • es6

    3.1 const 3.2 解构赋值 3.3 正则拓展 3.4 字符串拓展 ES7提案 3.6 数值拓展 3.7 ...

  • 3、字符串的拓展

    三、字符串的拓展 #3.1 includes(),startsWith(),endsWith() 在我们判断字符串...

  • 字符串,函数,数组,对象

    字符串 1.多行字符串 2.字符串模板 数组 1.拓展 就是相当于把这个数组的项拿出来 2.应用(函数参数的拓展)...

  • 常用的ES2015中的字符串、数值、数组的拓展方法

    一、字符串的拓展 1、使用for ... of循环字符串中的字符 2、利用includes、startsWith、...

  • JavaScript 字符串

    js字符串,js字符串的概述和声明,js字符串的特性,js字符串的常用方法,js字符串的拓展方法,js字符串的案例...

  • 字符串的拓展

    新加了 includes() startsWith() endsWith()三种查找字符串的方法 这三种方法相比...

  • 字符串的拓展

    1、includes() 返回布尔值,表示是否找到了参数字符串。 2、startsWith() 返回布...

  • JavaScript字符串倒置

    现有字符串varstr =“abcdefghk”,请为字符串类拓展一个reverse方法实现字符串的倒置,当str...

  • es6部分常用功能

    1 字符串的拓展 startsWith() 以...开始 endWith()以...结束 inc...

  • split分割字符串

    :字符串既有中文又有英文逗号 (2) 以 中文 或 英文 逗号分割字符串:字符串既有中文又有英文逗号 拓展:使用正...

网友评论

      本文标题:字符串的拓展

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