Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

292
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda