es6语法中新增哪些操作字符串方法,下面web建站小编给大家详细介绍一下具体实现方法!
复制代码let str = 'A';
console.log('输出结果:', str.codePointAt(0)) // 输出结果:65
- 1
- 2
String.fromCodePoint()
复制代码let str = String.fromCharCode(0x20BB7);
console.log('输出结果:', str) // 输出结果:ஷ
- 1
- 2
字符串的遍历器接口 for of
复制代码for (let str of '12345678') {
console.log('输出结果:', str)
}
//输出结果: 1
//输出结果: 2
//输出结果: 3
//输出结果: 4
//输出结果: 5
//输出结果: 6
//输出结果: 7
//输出结果: 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
at()
复制代码console.log('输出结果:', 'abcd'.at(2))
//输出结果: c
- 1
- 2
复制代码'\u01D1'==='\u004F\u030C' //false
'\u01D1'.length // 1
'\u004F\u030C'.length // 2
- 1
- 2
- 3
includes()
复制代码let str = 'Hello world!'; str.startsWith('Hello') // true
- 1
- 2
startsWith()
复制代码let str = 'Hello world!'; str.endsWith('Hello') // true
- 1
- 2
endsWith()
复制代码let str = 'Hello world!';
str.includes('Hello') // true
- 1
- 2
复制代码console.log('输出结果:', 'abcde'.padStart(2, 'ab')) //输出结果: abcde
console.log('输出结果:', 'abcde'.padEnd(2, 'ab')) //输出结果: abcde
- 1
- 2
标签: codePointAt, endsWith, es6字符串方法, es6语法, includes, normalize, padEnd, padStart, startsWith
上面是“es6语法中新增哪些操作字符串方法”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3877.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!