I stored the data in JSON format using the setItem method:
localStorage.setItem('orderproduct', JSON.stringify([{imageSource: productImg, productTitle: title, productQuantity: qty, productPrice: finalprice}]));
When I inspect it, this is how it appears:
imageSource: "http://127.0.0.1:5500/allproductIMG/cake1.png"
productPrice: 490
productQuantity: "5"
productTitle: "Hazelnut Praline Cake"
Now, when I try to retrieve the "productTitle" from JSON, I use the following method:
let productdata = JSON.parse(localStorage.getItem('orderproduct'));
'orderproduct' is the variable where the data is stored. However, when I check the productTitle using console.log:
console.log("The product title is"+ productdata.productTitle);
The result shows that 'productTitle' is undefined. Why is this happening? How can I retrieve the value "Hazelnut Praline Cake" instead of "undefined"