ES6---字符串新增方法

<script>
        //es6新增的四个关于字符串的方法
        //字符串是否包含字母
        var test = "helloMocha";
        console.log("helloMocha字符串中是否存在h:"+test.includes("h"));
        console.log("helloMocha字符串中是否存在p:"+test.includes("p"));
        //字符串以...开头
        console.log("helloMocha是否以h开头:"+test.startsWith("h"));
        //字符串以...结尾
        console.log("helloMocha字符串是否以h结尾:"+test.endsWith("h"));
        //重复字符串
        console.log(test.repeat(10));
    </script>

猜你喜欢

转载自blog.csdn.net/qq_39111062/article/details/80556315