TextEncoder

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

TextEncoder はコードポイントのストリームを入力として受け取り、 UTF-8 のバイトストリームを出力します。

メモ: この機能はウェブワーカー内で利用可能です。

コンストラクター

TextEncoder()

新たに生成した TextEncoder を返します。これは、 UTF-8 エンコーディングのバイトストリームを生成します。

インスタンスプロパティ

TextEncoder インターフェイスは、何もプロパティを継承していません。

TextEncoder.prototype.encoding 読取専用

常に utf-8 を返します。

インスタンスメソッド

TextEncoder インターフェイスは、何もメソッドを継承していません。

TextEncoder.encode()

入力として文字列を取り、 UTF-8 でエンコードされたテキストを含む Uint8Array を返します。

TextEncoder.encodeInto()

エンコードする文字列と、 UTF-8 でエンコードされたテキストをが入る宛先の Uint8Array を取り、エンコーディングの進捗を示す辞書オブジェクトを返します。これは encode() よりも新しく、より性能が高くなる可能性があります。

js
const encoder = new TextEncoder();
const view = encoder.encode("€");
console.log(view); // Uint8Array(3) [226, 130, 172]

仕様書

Specification
Encoding
# interface-textencoder

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
TextEncoder
TextEncoder() constructor
encode
encodeInto
encoding
Available in workers

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.

関連情報