Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
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 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!