I am currently trying to store an array into sessionStorage
and then retrieve the data from sessionStorage
. Then, store the sessionStorage
data back into an array.
var testArray = ["Shirt", "Bottom", "Shoes"];
window.sessionStorage.setItem("items", JSON.stringify(testArray));
var storedArray = JSON.parse('[' + sessionStorage.getItem("items") + ']');
var i;
for (i = 0; i < storedArray.length; i++) {
alert(storedArray[i]);
}
Am I doing anything wrong here?
JSON.parse(sessionStorage.getItem("items"));
.. What made you concatenate[ \ ]
there.. ? – Alexina