I'm currently developing a website where some data is stored within the session. In the initial page, I need to verify if the JSON object already exists in the session. Below is the code snippet that's causing issues:
var passedTotal = JSON.parse(sessionStorage.getItem('test total array'));
if(passedTotal.hasOwnProperty('letterplaatnaam')){
//do something
}
If the JSON object exists, everything works fine. But if it doesn't exist, the following error occurs:
Uncaught TypeError: Cannot read property 'hasOwnProperty' of null
I understand that this error is due to the object being empty. I've searched through various Stack Overflow questions but haven't found a solution yet. If you need more information, feel free to ask.