• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

190
Vistas
Unexpected token u in JSON at position 0 while using local storage

Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse () at index.js:4:20.

Want to store data in local storage but it showing this error code below

var todoArr = JSON.parse(localStorage.getItem("todoLocal")) || [];
about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to check to see if something is there before you parse it.

Either

var todoArr = localStorage.getItem("todoLocal") ? JSON.parse(localStorage.getItem("todoLocal")) : [];

// var lsTDL = localStorage.getItem("todoLocal");
// var todoArr =  lsTDL ? JSON.parse(lsTDL) : [];

or

var todoArr = JSON.parse(localStorage.getItem("todoLocal") || '[]');
about 3 years ago · Juan Pablo Isaza Denunciar
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda