字符串原型方法

常见有34种(去除已经弃掉的方法):

  1. String.prototype.at()
  2. String.prototype.charAt()
  3. String.prototype.charCodeAt()
  4. String.prototype.codePointAt()
  5. String.prototype.concat()
  6. String.prototype.endsWith()
  7. String.prototype.includes()
  8. String.prototype.indexOf()
  9. String.prototype.isWellFormed()
  10. String.prototype.lastIndexOf()
  11. String.prototype.localeCompare()
  12. String.prototype.match()
  13. String.prototype.matchAll()
  14. String.prototype.normalize()
  15. String.prototype.padEnd()
  16. String.prototype.padStart()
  17. String.prototype.repeat()
  18. String.prototype.replace()
  19. String.prototype.replaceAll()
  20. String.prototype.search()
  21. String.prototype.slice()
  22. String.prototype.split()
  23. String.prototype.startsWith()
  24. String.prototype.substring()
  25. String.prototype.toLocaleLowerCase()
  26. String.prototype.toLocaleUpperCase()
  27. String.prototype.toLowerCase()
  28. String.prototype.toString()
  29. String.prototype.toUpperCase()
  30. String.prototype.toWellFormed()
  31. String.prototype.trim()
  32. String.prototype.trimEnd()
  33. String.prototype.trimStart()
  34. String.prototype.valueOf()

其他,String 类型自身属性:

  1. String.prototype[@@iterator]()
  2. String.raw({raw: ['a', 'b', 'c']})
  3. String.fromCharCode()
  4. 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() 返回字符串对象的值
相关推荐
BillKu3 小时前
Vue3 + Element-Plus 抽屉关闭按钮居中
前端·javascript·vue.js
DevilSeagull3 小时前
JavaScript WebAPI 指南
java·开发语言·javascript·html·ecmascript·html5
面向星辰3 小时前
html中css的四种定位方式
前端·css·html
Async Cipher4 小时前
CSS 权重(优先级规则)
前端·css
大怪v4 小时前
前端佬:机器学习?我也会啊!😎😎😎手“摸”手教你做个”自动驾驶“~
前端·javascript·机器学习
Liquad Li4 小时前
Angular 面试题及详细答案
前端·angular·angular.js
用户21411832636025 小时前
首发!即梦 4.0 接口开发全攻略:AI 辅助零代码实现,开源 + Docker 部署,小白也能上手
前端
gnip7 小时前
链式调用和延迟执行
前端·javascript
SoaringHeart7 小时前
Flutter组件封装:页面点击事件拦截
前端·flutter
杨天天.7 小时前
小程序原生实现音频播放器,下一首上一首切换,拖动进度条等功能
前端·javascript·小程序·音视频