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

144
Visualizações
Console.log display object but save in localstorage is [object Object]

I use function parseJwt to convert token, in console it display object, but when i save it in localstorage it display [object Object], and i cant use JSON.parse it in another component

Console.log In localstorage enter image description here

     localStorage.setItem('response', parseJwt(JSON.stringify(response.data.token)));
      console.log(parseJwt(JSON.stringify(response.data.token)));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Local storage only supports storing string. So when you try storing an object like that, it won't work as expected. All you need to do, is stringify the object first:

localStorage.setItem('response', JSON.stringify(parseJwt(JSON.stringify(response.data.token))));

And the reason why you're seeing [object Object], is that [object Object] is the default string representation of a JavaScript Object. You can read more about here https://stackoverflow.com/questions/4750225/what-does-object-object-mean#:~:text=%5Bobject%20Object%5D%20is%20the%20default%20string%20representation%20of%20a%20JavaScript,alert(o)%3B%20%2F%2F%20foo

about 4 years ago · Juan Pablo Isaza Relatório
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