For some reason, I am facing an issue with using browser local storage to store an array. When testing it out, both indexes of the array are returning "null". Can someone help me identify what's going wrong?
window.localStorage.clear();
var requesterID = "ABC";
var title = "title";
if (window.localStorage.getItem("alreadyGotLastForAWeek") == null) {
window.localStorage.setItem("alreadyGotLastForAWeek", JSON.stringify(["placeHolder1"]));
}
window.localStorage.setItem("alreadyGotLastForAWeek", JSON.stringify(JSON.parse(window.localStorage.getItem("alreadyGotLastForAWeek")).push(requesterID+title)));
var tempArray = JSON.parse(window.localStorage.getItem("alreadyGotLastForAWeek"));
console.log(tempArray[0]);
console.log(tempArray[1]);
Expected Result:
placeHolder1
ABCtitle
Actual Result:
null
null