字符串原型方法

常见有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() 返回字符串对象的值
相关推荐
前端若水1 小时前
会话管理:创建、切换、删除对话历史
前端·人工智能·python·react.js
Bigger1 小时前
mini-cc:一个轻量级 AI 编程助手的诞生
前端·ai编程·claude
涵涵(互关)1 小时前
Naive-ui树型选择器只显示根节点
前端·ui·vue
BY组态1 小时前
Ricon组态系统最佳实践:从零开始构建物联网监控平台
前端·物联网·iot·web组态·组态
BY组态1 小时前
Ricon组态系统vs传统组态软件:为什么选择新一代Web组态平台
前端·物联网·iot·web组态·组态
SoaringHeart1 小时前
Flutter进阶:OverlayEntry 插入图层管理器 NOverlayZIndexManager
前端·flutter
放下华子我只抽RuiKe52 小时前
React 从入门到生产(四):自定义 Hook
前端·javascript·人工智能·深度学习·react.js·自然语言处理·前端框架
XinZong2 小时前
OpenClaw 实现双重心跳(Heartbeat)+ clawreach虾聊项目实现
javascript
IT_陈寒3 小时前
Redis缓存击穿把我整不会了,原来还有这手操作
前端·人工智能·后端
idcu3 小时前
深入 Lyt.js 组件系统:L2 渲染引擎层的核心
前端·typescript