Reading the documentation at MDN, it says
The TextEncoder.prototype.encode() method takes a USVString as input, and returns a Uint8Array containing the text given in parameters encoded with the specific method for that TextEncoder object.
On the other hand in the code below, each character in the string is transformed into its Unicode value and put into an array.
Uint8Array.from(
Array.from(value)
.map((letter) =>
letter.charCodeAt(0)
)
)
Often the two methods result in the same output, but sometimes with TextEncoder a longer TypedArray is generated, especially when the string to encode is a decoded encryption key.
I wonder why this is? Is this to do with the transformation from a JS string primative into a USVString? Or perhaps different encoding schemes?