add to an array of arrays localstorage code example
Example 1: localsstorage array append element
function addEntry() {
var existingEntries = JSON.parse(localStorage.getItem("allEntries"));
if(existingEntries == null) existingEntries = [];
var entryTitle = document.getElementById("entryTitle").value;
var entryText = document.getElementById("entryText").value;
var entry = {
"title": entryTitle,
"text": entryText
};
localStorage.setItem("entry", JSON.stringify(entry));
existingEntries.push(entry);
localStorage.setItem("allEntries", JSON.stringify(existingEntries));
};
Example 2: javascript store array in localstorage
var colors = ["red","blue","green"];
localStorage.setItem("my_colors", JSON.stringify(colors));
var storedColors = JSON.parse(localStorage.getItem("my_colors"));
Example 3: localstorage save array
var names = [];
names[0] = prompt("New member name?");
localStorage.setItem("names", JSON.stringify(names));
var storedNames = JSON.parse(localStorage.getItem("names"));