TextEncoder and TextDecoder using JavaScriptJavaScript TextEncoder and TextDecoder are the functions to encode and decode the given value, respectively. The TextEncoder works to convert a specified string into the utf-8 standard using the JavaScript function. It transforms the string into a Uint8Array. Using a JavaScript function, the TextDecoder converts specific input bytes into a required code point. It can decode ISO-8859-2, KOI8-R, UTF-8, GBK, and other file types. TextDecoder using JavaScriptThe function can read the value into a JavaScript string using the built-in TextDecoder object. SyntaxFirstly, we can use the following syntax to decode the input value.
Decoding comes next, and it works like this:
ExamplesThe following examples show the different types of data to decode the data. Example1 The following example shows the given objects of the input label. We can see the decoded data of the input stream or string. Here, the example uses, by default, "Uint8Array" encoded values. Output The following image shows the decoding data of the input value. Example2 The following example shows the given objects of the input label. We can see the decoded data of the input stream or string. We can use the onclick button with the event to display data. We can see the upper-case and lower-case encoded data with other encoded information. Output The following image shows the decoding data of the input value. Example3 The following example shows TextDecoder with the sub-array using objects of the input label. We can see the decoded data of the input stream or string with the given array length. We can use the onclick button with the event to display data. Output The following image shows the decoding data of the input value. TextEncoder using JavaScriptThe function can read the value into a JavaScript string using the built-in TextDecoder object. SyntaxFirstly, we can use the following syntax to decode the input value.
Secondly, the encode function is used after the TextEncoder method.
ExamplesThe following examples show the different types of data to encode the data. Example1 The following example shows the given objects of the input label encoded in the required format. We can see the encoded data of the input object from the string. Here, the example uses, by default, "Uint8Array" encoded values. Output The following image shows encoding data of the input value. Example2 The following example shows the given objects of the input label. We can see the decoded data of the input stream or string. We can use the onclick button with the event to display data. We can see the upper-case and lower-case encoded data with other encoded information. Output The following image shows encoding data of the input value. Example3 The following example shows the given objects of the input label. We can see the decoded data of the input stream or string. We can use the onclick button with the event to display data. We can see the substring of the entire string. Output The following image shows encoding data of the input value. Examples of TextEncoder and TextDecoderThe following example shows the combination of the TextEncoder and TextDecoder in JavaScript. Output The following image shows encoding data of the input value. ConclusionThe TextEncoder and TextDecoder in JavaScript help to encode and decode the value. It helps to secure and private the data. Next TopicJavascript nullish coalescing operator |