1、TextEncoder();
- [TextEncoder()方法从 Firefox 48 and Chrome 53 开始不再需要参数;](https://developer.mozilla.org/zh-CN/docs/Web/API/TextEncoder/TextEncoder)
TextEncode对象内置了encoding属性和encode()方法; - TextEncoder.encoding 只读属性返回一个DOMString ,其中包含特定编码器使用的编码算法的名称。
- TextEncoder.encode(String);接收一个String类型的参数返回一个Unit8Array;
- 用法:
const encoder = new TextEncode();
console.log(encoder.encode(‘hhhh’));
// 输出结果
2、TextDecode()
TextDecode()用法同TextEncode(),用来对使用TextEncode对象编码的字符串做解码处理;- 用法:
const decoder = new TextDecode();
console.log(decoder.decode(encoder.encode(‘hhhh’))); // 输出’hhhh’;
- 用法: