ES6参考---字符串扩展

ES6参考---字符串扩展

一、总结

一句话总结:

1、includes(str) : 判断是否包含指定的字符串
2、startsWith(str) : 判断是否以指定字符串开头
3、endsWith(str) : 判断是否以指定字符串结尾
4、repeat(count) : 重复指定次数:str.repeat(5)
    let str = 'abcdefg';
    console.log(str.includes('a'));//true
    console.log(str.includes('h'));//false

    //startsWith(str) : 判断是否以指定字符串开头
    console.log(str.startsWith('a'));//true
    console.log(str.startsWith('d'));//false
    //endsWith(str) : 判断是否以指定字符串结尾
    console.log(str.endsWith('g'));//true
    console.log(str.endsWith('d'));//false
    //repeat(count) : 重复指定次数a
    console.log(str.repeat(5));

二、字符串扩展

博客对应课程的视频位置:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4   <meta charset="UTF-8">
 5   <title>01_字符串扩展</title>
 6 </head>
 7 <body>
 8 <!--
 9 1. includes(str) : 判断是否包含指定的字符串
10 2. startsWith(str) : 判断是否以指定字符串开头
11 3. endsWith(str) : 判断是否以指定字符串结尾
12 4. repeat(count) : 重复指定次数
13 -->
14 <script type="text/javascript">
15 
16     let str = 'abcdefg';
17     console.log(str.includes('a'));//true
18     console.log(str.includes('h'));//false
19 
20     //startsWith(str) : 判断是否以指定字符串开头
21     console.log(str.startsWith('a'));//true
22     console.log(str.startsWith('d'));//false
23     //endsWith(str) : 判断是否以指定字符串结尾
24     console.log(str.endsWith('g'));//true
25     console.log(str.endsWith('d'));//false
26     //repeat(count) : 重复指定次数a
27     console.log(str.repeat(5));
28 </script>
29 </body>
30 </html>
 
原文地址:https://www.cnblogs.com/Renyi-Fan/p/12589579.html