Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda