1、 split() 方法用于把一個(gè) 字符串 分割成 字符串?dāng)?shù)組
var str = "123,456,789";
console.log(str.split('')); // ["1", "2", "3", ",", "4", "5", "6", ",", "7", "8", "9"]
console.log(str.split(',')); // ["123", "456", "789"]
2、 slice() 可提取字符串的某個(gè)部分,并以新的字符串返回被提取的部分
var str = "123,456,789";
console.log(str.slice(2,6)); // 3,45
console.log(str.slice(-6,-2)); // 56,7
console.log(str.slice(2)); // 3,456,789
console.log(str.slice(-6)); // 56,789
3、substring() 提取字符串中介于兩個(gè)指定下標(biāo)之間的字符
var str = "123,456,789";
console.log(str.substring(2,6)); // 3,45
console.log(str.substring(2)); // 3,456,789
console.log(str.substring(6,2)); // 3,45
console.log(str.substring(-6,-2)); //
console.log(str.substring(6,6)); //
4、join() 把數(shù)組中的所有元素轉(zhuǎn)換一個(gè)字符串
var str = [123,456,789];
console.log(str.join('')); // 123456789
console.log(str.join(',')); // 123,456,789
5、 charAt() 返回指定位置的字符文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-605497.html
var str='0123456';
str.charAt(1); //1
https://blog.csdn.net/weixin_45103130/article/details/123731281文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-605497.html
到了這里,關(guān)于js截取字符串的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!