I am building a website and can't understand how to pass arrays across different web pages of the same website. The code for defining the array is:
sessionStorage.setItem("hello", JSON.stringify(["hi", "sup"]));
The code for calling the array on the second page is:
var helloArray = JSON.parse(sessionStorage.getItem("hello"));
When I loop through the array with this code:
for (var i = 0; i < helloArray.length; i++) {
// JavaScript code
}
It creates an error that says: Uncaught TypeError: Cannot read property 'length' of null
.
What can I change and what did I do wrong?