定义一个字符串(原始数据)
将其使用utf8编码成一个数组(编码)
再将其解码成一个字符串(还原)
let str1 = "我们①this is a string";
//我们①this is a string
console.log(str1);
const byteArray = new TextEncoder().encode(str1);
//Uint8Array(25) [
// 230, 136, 145, 228, 187, 172,
// 226, 145, 160, 116, 104, 105,
// 115, 32, 105, 115, 32, 97,
// 32, 115, 116, 114, 105, 110,
// 103
//]
console.log(byteArray);
//19
console.log(str1.length);
//25
console.log(byteArray.length);
//我们①this is a string
console.log(new TextDecoder().decode(byteArray));