Using Uint16Array on ArrayBuffer to encode and decode characters in Javascript

Опубликовано: 20 Апрель 2026
на канале: Logan Lee
425
3

This is a follow up of ArrayBuffer video from last time.

This time we use Utf-16 encoding to encode and decode characters. This answers the question about how to assign non-numerical values to a TypedArray. We simply choose an encoding for it then use String.prototype's built-in methods.

We use String.prototype.charCodeAt function to encode a character from string.

On the opposite direction, we use String.prototype.fromCharCode function to convert character code back to string.

Have a look at jsfiddle code below for demo.

Refer: https://jsfiddle.net/6audtywx/4/
Refer: http://www.fileformat.info/info/chars...