//The codePointAt() Method
let text = "????";
console.log(text.length);
console.log(/^.$/.test(text));
console.log(text.charAt(0));
console.log(text.charAt(1));
console.log(text.charCodeAt(0));
console.log(text.charCodeAt(1));
let text = "????a";
console.log(text.charCodeAt(0));
console.log(text.charCodeAt(1));
console.log(text.charCodeAt(2));
console.log(text.codePointAt(0));
console.log(text.codePointAt(1));
console.log(text.codePointAt(2));
function is32Bit(c) {
return c.codePointAt(0) > 0xFFFF;
}
console.log(is32Bit("????")); // true
console.log(is32Bit("a")); // false
//The String.fromCodePoint() Method
console.log(String.fromCodePoint(134071)); // "????"
//The u Flag in Action
let text = "????";
console.log(text.length);
console.log(/^.$/.test(text));
console.log(/^.$/u.test(text));
//Counting Code Points
function codePointLength(text) {
let result = text.match(/[\s\S]/gu);
return result ? result.length : 0;
}
console.log(codePointLength("abc")); // 3
console.log(codePointLength("????bc")); // 3
//Methods for Identifying Substrings
let msg = "Hello world!";
console.log(msg.startsWith("Hello"));
console.log(msg.endsWith("!"));
console.log(msg.includes("o"));
console.log(msg.startsWith("o"));
console.log(msg.endsWith("world!"));
console.log(msg.includes("x"));
console.log(msg.startsWith("o", 4));
console.log(msg.endsWith("o", 8));
console.log(msg.includes("o", 8));
ES6
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.