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

152
Visualizações
String to hex TypedArray.map different from Array.from(TypedArray)

String to hex is the goal. Getting a different result when using map directly on a TypedArray vs using Array.from on the TypedArray then using map. Can someone help me understand what is going on?

var buf = new TextEncoder().encode('hello');

var ret = '';
for (var b of buf) ret += b.toString(16).padStart(2, '0').slice(-2);

console.log(
    '\n',
    buf.join(), // 104,101,108,108,111
    '\n',
    buf.map(x => x.toString(16).padStart(2, '0').slice(-2)).join(''), // 6865000 
    '\n',
    Array.from(buf).join(), // 104,101,108,108,111 
    '\n',
    Array.from(buf).map(x => x.toString(16).padStart(2, '0').slice(-2)).join(''), // 68656c6c6f 
    '\n',
    ret, // 68656c6c6f 
    '\n',
    decodeURIComponent('%' + ret.match(/.{1,2}/g).join('%')) // hello
);
/*
 104,101,108,108,111 
 6865000 
 104,101,108,108,111 
 68656c6c6f 
 68656c6c6f 
 hello
*/
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