Skip to content
本页目录

String 字符串

构造函数

String()

静态方法

实例属性

  • String.prototype.length 字符串长度,只读属性

实例方法

查找与包含

方法参数说明返回值
atindex支持负值,从后往前下标对应的字符,不存在返回 undefined
charAtindex与 at 相似,不支持负值下标对应的字符,不存在返回空字符串
indexOfsearchString字符串第一次出现的索引,不存在返回 -1
includessearchString[, n]n 是从下标第几个才是查找字符串是否包含,包含true,不包含false
startsWithsearchString同上
endsWithsearchString

增删改

方法参数说明返回值
concatitem1, item2...项目一般使用 + 连接操作符合并两个(或更多)字符串的文本并返回新字符串
repeatcount"abc".repeat(2) // "abcabc"返回新字符串
replace
replaceAll
slicebeginIndex[, endIndex]返回截取字符串组成的新字符串
substringindexStart[, indexEnd]返回截取字符串组成的新字符串

其它方法

方法参数说明返回值
splitseparator[, limit]字符串拆分拆分成的数组
toUpperCase
toLowerCase
trim删除字符头尾空白字符,返回新字符串
trimStart
trimEnd
valueOf