The TextDecoder.decode()
method returns a string containing text decoded from the buffer passed as a parameter.
The decoding method is defined in the current TextDecoder
object. This includes the expected encoding of the data, and how decoding errors are handled.
decode()
decode(buffer)
decode(buffer, options)
This example encodes and decodes the euro symbol, €.
<p>Encoded value: <span id="encoded-value"></span></p>
<p>Decoded value: <span id="decoded-value"></span></p>
const encoder = new TextEncoder();
const array = encoder.encode("€");
document.getElementById("encoded-value").textContent = array;
const decoder = new TextDecoder();
const str = decoder.decode(array);
document.getElementById("decoded-value").textContent = str;