2024年06月24日 建站教程
es6语法中新增哪些操作字符串方法,下面web建站小编给大家详细介绍一下具体实现方法!
let str = 'A';
console.log('输出结果:', str.codePointAt(0)) // 输出结果:65
String.fromCodePoint()
let str = String.fromCharCode(0x20BB7);
console.log('输出结果:', str) // 输出结果:ஷ
字符串的遍历器接口 for of
for (let str of '12345678') {
console.log('输出结果:', str)
}
//输出结果: 1
//输出结果: 2
//输出结果: 3
//输出结果: 4
//输出结果: 5
//输出结果: 6
//输出结果: 7
//输出结果: 8
at()
console.log('输出结果:', 'abcd'.at(2))
//输出结果: c
'\u01D1'==='\u004F\u030C' //false '\u01D1'.length // 1 '\u004F\u030C'.length // 2
includes()
let str = 'Hello world!'; str.startsWith('Hello') // true
startsWith()
let str = 'Hello world!'; str.endsWith('Hello') // true
endsWith()
let str = 'Hello world!';
str.includes('Hello') // true
console.log('输出结果:', 'abcde'.padStart(2, 'ab')) //输出结果: abcde
console.log('输出结果:', 'abcde'.padEnd(2, 'ab')) //输出结果: abcde
本文链接:http://so.lmcjl.com/news/7184/