Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

TextDecoder: TextDecoder() constructor

BaselineWidely available

Note: This feature is available inWeb Workers.

TheTextDecoder() constructor returns a newTextDecoder object.

Syntax

js
new TextDecoder()new TextDecoder(label)new TextDecoder(label, options)

Parameters

labelOptional

A string identifying the character encoding that this decoder will use. This may beany valid label.

Defaults to"utf-8".

optionsOptional

An object with the following properties:

fatalOptional

A boolean value indicating if theTextDecoder.decode() method must throw aTypeError when decoding invalid data.It defaults tofalse, which means that the decoder will substitute malformed data with a replacement character.

ignoreBOMOptional

A boolean value indicating whether thebyte order mark will be included in the output or skipped over.It defaults tofalse, which means that the byte order mark will be skipped over when decoding and will not be included in the decoded text.

Exceptions

RangeError

Thrown if the value oflabel is unknown, or is one of the values leading to a'replacement' decoding algorithm ("iso-2022-cn" or"iso-2022-cn-ext").

Examples

js
const textDecoder1 = new TextDecoder("iso-8859-2");const textDecoder2 = new TextDecoder();const textDecoder3 = new TextDecoder("csiso2022kr", { fatal: true });// Allows TypeError exception to be thrown.const textDecoder4 = new TextDecoder("iso-2022-cn");// Throws a RangeError exception.

Specifications

Specification
Encoding
# ref-for-dom-textdecoder①

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp