String对象方法at/charAt/charCodeAt/codePointAt/fromCodePoint/fromCharCode
at:获取对应索引位置的字符。传入负数表示从数组尾部计数
let str = "hello world";
console.log(str.at(1), str.at(7), str.at(-2));
charAt:获取对应索引位置的字符。传入负数则返回空字符串
let str = "abcdefg";
console.log(str.charAt(0), str.charAt(3));
console.log(str.charAt(-2));
charCodeAt:获取对应索引位置字符的ASCII码。传入负数则返回NaN
let str = "abcdefg";
console.log(str.charCodeAt(0), str.charCodeAt(3));
console.log(str.charCodeAt(-2));
codePointAt:获取对应索引位置字符的Unicode编码。传入负数则返回undefined
let str = "abcdefg";
console.log(str.codePointAt(0), str.codePointAt(3));
str = '\uD800\uDC00';
console.log(str.codePointAt(0));
console.log(str.codePointAt(-1));
fromCodePoint:通过ASCII码构造字符串
console.log(String.fromCharCode(97, 100, 190, 61));
fromCharCode:通过Unicode编码构造字符串
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2F804));