字符串原型方法
常见有34种(去除已经弃掉的方法):
- String.prototype.at()
- String.prototype.charAt()
- String.prototype.charCodeAt()
- String.prototype.codePointAt()
- String.prototype.concat()
- String.prototype.endsWith()
- String.prototype.includes()
- String.prototype.indexOf()
- String.prototype.isWellFormed()
- String.prototype.lastIndexOf()
- String.prototype.localeCompare()
- String.prototype.match()
- String.prototype.matchAll()
- String.prototype.normalize()
- String.prototype.padEnd()
- String.prototype.padStart()
- String.prototype.repeat()
- String.prototype.replace()
- String.prototype.replaceAll()
- String.prototype.search()
- String.prototype.slice()
- String.prototype.split()
- String.prototype.startsWith()
- String.prototype.substring()
- String.prototype.toLocaleLowerCase()
- String.prototype.toLocaleUpperCase()
- String.prototype.toLowerCase()
- String.prototype.toString()
- String.prototype.toUpperCase()
- String.prototype.toWellFormed()
- String.prototype.trim()
- String.prototype.trimEnd()
- String.prototype.trimStart()
- String.prototype.valueOf()
其他,String 类型自身属性:
String.prototype[@@iterator]()
- String.raw({raw: [‘a’, ‘b’, ‘c’]})
- String.fromCharCode()
- String.fromCodePoint()
太多了,如何记住字符串方法?
4 + 8 + 16 + 6 = 34种
获取单个字符(4):
- at()
- charAt()
- charCodeAt()
- codePointAt() 返回 unicode 码位
查找(8):
- startsWith()
- endsWith()
- includes() 区分大小写 数组同样也有
- indexOf()
- lastIndexOf()
- match() 正则
- matchAll()
- search()
操作(16):
- concat() 数组同样也有
- padStart()
- padEnd() 填充
- repeat() 重复
- replace() 原字符串不变
- replaceAll() 原字符串不变
- slice() 原字符串不变,数组有类似方法
- split() 转换为数组
- substring() 子串
- toLocaleLowerCase() 小写
- toLowerCase() 小写
- toLocaleUpperCase()
- toUpperCase()
- trim() 原字符串不变
- trimStart()
- trimEnd()
其他(6):
- isWellFormed() 是否包含单独代理项
- toWellFormed()
- localeCompare()
- normalize()
- toString()
- valueOf() 返回字符串对象的值