【js】截取字符串的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31083947/article/details/80140152
<script>
        var string  = "helloworld";
        //a:开始截取的位置  b:截取的长度
        string.substr(a,b);
        //a:开始截取的位置  b:结束截取的位置
        string.substring(a,b);

        string.substr(2);       //输出    "lloworld"
        string.substr(2,4);     //输出    "llow"   
        string.substring(2);    //输出    "lloworld" 
        string.substring(2,4)   //输出    "ll"

    </script>

猜你喜欢

转载自blog.csdn.net/qq_31083947/article/details/80140152