es6 字符串扩展

Posted 宝清老窖

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了es6 字符串扩展相关的知识,希望对你有一定的参考价值。

var s = ??;
var s1 = \ud842\uDFB7;
var s2 = \u{20BB7};

s1 === s2 //true

//js have 6 type express str
\z === z
//   ‘\172‘ === ‘z‘
\x7A === z
\u007A === z
\u{7A} === z

s.length = 2;
s.charAt(0) //‘?‘
s.charAt(1) //‘?‘
//charCodeAt
s.charCodeAt(0)
s.charCodeAt(1)
//codePointAt 用来处理4个字节的字符,返回一个字符的码点
var s =  ?? a
s.codePointAt(0)  //32
s.codePointAt(1)  //134071
s.codePointAt(2)  //57271
s.codePointAt(3)  //32
s.codePointAt(4)  //97
s.codePointAt(5)  //undefined

//String.fromCodePoint()   返回字符串
var text = String.fromCodePoint(0x20BB7) //"??"

//字符串的遍历器接口
for (var s of foo){console.log(foo)}
// f
// o
// o
for(var i = 0 ; i < text.length; i++){
  console.log(text[i]);
}
//?
//?
for (let i of text){
  console.log(i)
}

text.at(0)  //代替code

//normalize() pass

//includes(),startsWith(),endsWith()
var str = Hello world
str.startWidth(world,6) //true
str.endsWith(Hello,5) //true
str.includes(Hello, 6)  //false

//repeat
str.repeat(3) //"Hello worldHello worldHello world"

//padStart()    padEnd()
x.padStart(5,a)
x.padStart(3,a)

x.padEnd(5, a)
x.padEnd(3, a)

 

以上是关于es6 字符串扩展的主要内容,如果未能解决你的问题,请参考以下文章

ES6数组扩展运算符和字符串遍历的新方法!!!

ES6

前端面试计划(二)ES6「v2-附加代码」

ES6基础-ES6的扩展

ES6学习笔记(letconst变量的解构赋值字符串扩展)

ES6新特性