Recently delved into the world of Javascript and encountered a roadblock that I can't seem to overcome. Here's the snippet of code causing me trouble:
add = document.getElementById("add");
add.addEventListener("click", () => {
console.log("Please wait a while...Updating List...")
tit = document.getElementById('title').value;
des = document.getElementById('description').value;
if (localStorage.getItem('name') == null) {
itemJsonArray = []
itemJsonArray.push([tit, des])
localStorage.setItem('name', JSON.stringify(itemJsonArray))
}
else {
itemJsonArrayStr = localStorage.getItem('name')
itemJsonArray = JSON.parse(itemJsonArrayStr)
itemJsonArray.push([tit, des]);
localStorage.setItem('name', JSON.stringify(itemJsonArrayStr))
}
Upon calling localStorage.getItem('name'), an error is consistently thrown: Uncaught TypeError: itemJsonArray.push is not a function at HTMLButtonElement.
});
Below is the corresponding HTML markup:
Initially believed it would work flawlessly, but unfortunately, that was not the case...