The TextDecode.decode()
method returns a string containing the text, given in parameters, decoded with the specific method for that TextDecoder
> object.
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;