Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
JS - When is TextEncoder().encode different from an Array generated from each char's charCode

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!