//storing array in localStorage
var colors = ["red","blue","green"];
localStorage.setItem("my_colors", JSON.stringify(colors)); //store colors
var storedColors = JSON.parse(localStorage.getItem("my_colors")); //get them back
// our array
var movies = ["Reservoir Dogs", "Pulp Fiction", "Jackie Brown",
"Kill Bill", "Death Proof", "Inglourious Basterds"];
// storing our array as a string
localStorage.setItem("quentinTarantino", JSON.stringify(movies));
// retrieving our data and converting it back into an array
var retrievedData = localStorage.getItem("quentinTarantino");
var movies2 = JSON.parse(retrievedData);
//making sure it still is an array
alert(movies2.length);
//To store array of object in local storage
var msgObj ={
'msg': 'Kiran G',
'date':new Date().toLocaleString().replace(",", "")
}
let msgArr = JSON.parse(localStorage.getItem('msg')) ? JSON.parse(localStorage.getItem('msg')) : []
msgArr.push(msgObj)
localStorage.setItem('msg', JSON.stringify(msgArr))
// Guardar el array en el localStorage
// El arreglo:
var array = [1, 2, 3];
// Se guarda en localStorage despues de JSON stringificarlo
localStorage.setItem('myArray', JSON.stringify(array));
// Obtener el arreglo de localStorage
var array = localStorage.getItem('myArray');
// Se parsea para poder ser usado en js con JSON.parse :)
array = JSON.parse(array);