1.indexOf(str,index) 查找某个指定的字符串在字符串中首次出现的位置
示例:
//通过indexof查询s的位置,n出现的第一个位置,o出现的第一个位置分别是什么?
let v='honorificabilitudinitatibus';
document.write('s的位置'+v.indexOf('s',0)+'<br />');
document.write('n出现的第一个位置'+v.indexOf('n',0)+'<br />');
document.write('o出现的第二个位置'+v.indexOf('o',2));
2.charAt(index) 返回在指定位置的字符
示例:
//返回第七个字符
let b='forge ahead';
document.write(b.charAt(7));
3.toLowerCase() 把字符串转化为小写
示例:
let h='SJWOEIioi';
document.write(h.toLowerCase());
4.toUpperCase() 把字符串转化为大写
示例:
let h='SJWOEIioi';
document.write(h.toUpperCase());
5.substring(index1,index2) 返回位于指定索引 index1 和 index2 之间的字符串,并且包括索引 index1 对应的字符,不包括索引 index2 对应的字符
示例:
//查找19-27之间的字符
let h='remain true to the original aspiration';
document.write(h.substring(19,27));
6.split(str) 将字符串分割为字符串数组
示例:
let p='床前明月光,疑是地上霜,举头望明月,低头思故乡';
let zu=p.split(',');
document.write(zu[0]+"<br />"+zu[1]+"<br />"+zu[2]+"<br />"+zu[3]);