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

157
Views
How to get data from JSON using javascript

I have put the data in JSON by using the setItem method:

localStorage.setItem('orderproduct', JSON.stringify([{imageSource: productImg, productTitle: title, productQuantity: qty, productPrice: finalprice}]));

and I check in the inspect is like this:

imageSource: "http://127.0.0.1:5500/allproductIMG/cake1.png"
productPrice: 490
productQuantity: "5"
productTitle: "Hazelnut Praline Cake"

Now I want to get the "productTitle" from JSON, I use this method:

let productdata = JSON.parse(localStorage.getItem('orderproduct'));

which 'orderproduct' is the variable I used to store the data. After that I use console.log to check the productTitle :

console.log("The product title is"+ productdata.productTitle);

But, the answer shows the 'productTitle' is undefined. Why? How can I get the "Hazelnut Praline Cake" instead of "undefined"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You must destruct the array before accessing the inner object,

console.log("The product title is"+ productdata[0].productTitle);

Otherwise you can save it without the array

localStorage.setItem('orderproduct', JSON.stringify({imageSource: productImg, productTitle: title, productQuantity: qty, productPrice: finalprice}))
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!