Issue
I'm trying to pull data from the console on one page, written in json and then transfer it to another using this script, but I'm having problems. Help solve the problem)
JS code
chosen = JSON.parse(sessionStorage.getItem('chosen'))
console.log(chosen)
let s = "";
let sum = 0.0;
for (let [key, value] of Object.entries(chosen)) {
s += `<p>${key} (${value['value']}): \u20ac ${value['price']}</p>`
sum += parseFloat(value['price'])
}
s += `<p>Total: ${sum}</p>`
document.getElementById("components").innerHTML += s;
Error
order.js:6 Uncaught TypeError: Cannot convert undefined or null to object
at Function.entries (<anonymous>)
at order.js:6
Solution
Can you define your chosen variable correctly and try again?
This chosen = JSON.parse(sessionStorage.getItem('chosen'))
should be like this => const chosen = JSON.parse(sessionStorage.getItem('chosen'))
Answered By - cooskun
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.