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"