Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda