<script>
//字符串方法charAt(index)
//startswidth检测数组是否有指定的开头
//charAt字符串方法返回index值所对应的字符串值
let arr = 'Hellow word'
console.log(arr.charAt(1))//e
console.log(arr)
console.log(arr.length)
console.log(arr[5])
console.log(arr.indexOf('w'))
let a= Array.from(arr)
console.log(a)
// indexOf字符串方法两个参数,第一个参数要查的值,第二个参数,从什么地方开始没有查到就返回-1
let arr = 'Hellow word'
console.log(arr.indexOf('o',5))
// lastIndexOf字符串方法,第一个参数要查的值,第二个参数,从什么地方开始查,但是lastIndexOf是从尾部开始
let arr = 'Hellow word'
console.log(arr.lastIndexOf('w',8))
//substring字符串方法字符串截取第一个参数截取开始的位置,第二个参数结束的位置,第二个参数可以忽略表示从开始的位置到结束全部截取
let arr = 'Hellow word'
/console.log(arr.substring(2,7))
//substr字符串方法截取字符串第一个参数从什么地方开始截取,第二个参数截取的长度
let arr = 'Hellow word'
console.log(arr.substr(2,6))
//split字符串方法将字符串分割成数组通常用,号
let arr = 'Hellow word'
console.log(arr.split(","))
// replace字符串方法替换第一个参数要替换的的值,第二个参数要替换的内容
let arr = 'Hellow word'
console.log(arr.replace(/o/g,'a'))
不会还有人,还不知道js中字符串的所有方法吧
本文详细介绍了JavaScript中的字符串方法,如charAt(), indexOf(), lastIndexOf(), substring(), substr(), split(), replace()等,并通过实例演示了如何使用这些方法处理字符串。深入理解字符串操作有助于提升前端开发技能。





