textEncoder.encodeInto(src, dest)
src
<string> 要编码的文本。dest
<Uint8Array> 保存编码结果的数组。- 返回: <Object>
将 src
字符串 UTF-8 编码为 dest
Uint8Array 并返回包含读取的 Unicode 代码单元和写入的 UTF-8 字节的对象。
const encoder = new TextEncoder();
const src = 'this is some data';
const dest = new Uint8Array(10);
const { read, written } = encoder.encodeInto(src, dest);
src
<string> The text to encode.dest
<Uint8Array> The array to hold the encode result.- Returns: <Object>
UTF-8 encodes the src
string to the dest
Uint8Array and returns an object
containing the read Unicode code units and written UTF-8 bytes.
const encoder = new TextEncoder();
const src = 'this is some data';
const dest = new Uint8Array(10);
const { read, written } = encoder.encodeInto(src, dest);