var str : string = "魑魅魍魉"; console.log("str:", str); console.log("str len:", str.length); var enc : TextEncoder = new TextEncoder(); var dec : TextDecoder = new TextDecoder(); var buf : Uint8Array = enc.encode(str); console.log("buf:", buf); console.log("buf len:", buf.length); for (var i = 0; i <= buf.length; i++) { console.log(`buf[${i}]: ${ dec.decode(buf.slice(0, i)) }`); }