“Store Array in LocalStorage” Code-Antworten

JavaScript Store Array in LocalStorage

//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
Grepper

Store Array in LocalStorage

var names = [];
names[0] = prompt("New member name?");
localStorage.setItem("names", JSON.stringify(names));

//...
var storedNames = JSON.parse(localStorage.getItem("names"));
Wandering Wryneck

LOCALSTORAGE JavaScript -Array

// 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);
Pepiño

Ähnliche Antworten wie “Store Array in LocalStorage”

Fragen ähnlich wie “Store Array in LocalStorage”

Weitere verwandte Antworten zu “Store Array in LocalStorage” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen