【持续记录】js字符串

1.字符串截取
字符串.slice(startIndex, lastIndex),前闭后开区间,从包含startIndex位置截取到不包含lastIndex位置的字符串

        let str = 'helloWorld';
        let res1 = str.slice(0,3);// 截取索引0、1、2字符
        console.log(res1);//hel
        let res2 = str.slice(3,6);// 截取索引3、4、5字符
        console.log(res2);//loW
        let res3 = str.slice(3);// 从索引3开始截取后面所有
        console.log(res3);//loWorld

Guess you like

Origin blog.csdn.net/JWbonze/article/details/120998476