美文网首页
ES6-基础数据类型新增的方法[String]

ES6-基础数据类型新增的方法[String]

作者: 吴高亮 | 来源:发表于2018-12-23 22:51 被阅读0次

字符串的扩展

  1. 字符的 Unicode 表示法
  2. codePointAt()
  3. String.fromCodePoint()
  4. 字符串的遍历器接口
  5. normalize()
  6. includes(), startsWith(), endsWith()
  7. repeat()
  8. padStart(),padEnd()
  9. matchAll()
  10. 模板字符串
  11. 实例:模板编译
  12. 标签模板
  13. String.raw()
  14. 模板字符串的限制
  • ES6为字符串增加了便利的接口;
  • 新增三个API
    1:includes;指定字符串中是否含有某个串;
    2:startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
    3: endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
let str='hello world!';
str.includes('hello');//true
str.starsWith('h');/true;
str.startsWith('e');//false;
str.endsQWith('!');//true;
  • repeat方法返回一个新字符串,表示将原字符串重复n次。
'x'.repeat(3) // "xxx"
'hello'.repeat(2) // "hellohello"
'na'.repeat(0) // ""

-padSart padEnd;
padStart()用于头部补全,padEnd()用于尾部补全。

'x'.padStart(5, 'ab') // 'ababx'
'x'.padStart(4, 'ab') // 'abax'

'x'.padEnd(5, 'ab') // 'xabab'
'x'.padEnd(4, 'ab') // 'xaba'

比较重要的是字符串,模板;写法如下

`
<ul>
  <li>${变量}</li>
  <li>second</li>
</ul>
`
使用``包裹DOM元素;使用${};在大括号中可以使用简单的js的逻辑操作;

其他的想要了解更多的直接点击上面的每一个超链接就可以访问;

相关文章

网友评论

      本文标题:ES6-基础数据类型新增的方法[String]

      本文链接:https://www.haomeiwen.com/subject/npuokqtx.html