LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 219|回复: 0

TextEncoder

[复制链接]
发表于 2024-1-31 22:57:27 | 显示全部楼层 |阅读模式
TextEncoder 做相反的事情 —— 将字符串转换为字节。

语法为:

let encoder = new TextEncoder();
只支持 utf-8 编码。

它有两种方法:

encode(str) —— 从字符串返回 Uint8Array。
encodeInto(str, destination) —— 将 str 编码到 destination 中,该目标必须为 Uint8Array。
let encoder = new TextEncoder();

let uint8Array = encoder.encode("Hello");
alert(uint8Array); // 72,101,108,108,111

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表