0

Please help. I need my array to save when I goto another page. Since the page refreshes it loses the array. From here my code stops at the beginning of the store it function when I try to use sessionstorage.

Here is my attempt. The array part is just to remove the duplicate from and array and place it into array b. HTML:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Session Storage Attempt</title>
    <script src="untitled-1.js" type="text/javascript"></script>
</head>

<body>
    <button onClick="doIt()">Button</button>
    <br>
    <br>
    <button onClick="storeIt()">Store It</button>
</body>
</html>

Javascript:

let a = [];
let b = [];

function doIt(){
    a.push("a");
    let len = a.length;
    for(let i = 0; i < len; i++){
        if(b.indexOf(a[i]) === -1){
            b.push(a[i]);
        }
    }
    alert(b);
}


function storeIt(){
    sessionStorage.setItem('bee', JSON.stringify(b));
    JSON.parse(sessionStorage.getItem('bee'));

    alert(bee);
}
Jay
  • 64
  • 7

0 Answers0