首页 > 代码库 > es6 字符串扩展
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 字符串扩展
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。