Ok, I've tried to follow examples here, I know there might be a few different ways of adding objects to an array in localstorage and not overwriting it but I'm failing to find at least one of them.
Got this code to store objects in array but it's overwriting itself. May anyone show me what am I missing? (And I'm afraid I could be missing a lot).
function addEntry() {
var entryTitle = document.getElementById("entryTitle").value;
var entryText = document.getElementById("entryText").value;
var entry = {
"title": entryTitle,
"text": entryText
};
localStorage.setItem("entry", JSON.stringify(entry));
var allEntries = [];
allEntries.push(entry);
localStorage.setItem("allEntries", JSON.stringify(allEntries));
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…