“LOCALSTORAGE SAVE Array” 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

LOCALSTORAGE SAVE Array

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

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

How-to-Save-Array im lokalen Speicher-JS

// 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);
Omar

Ähnliche Antworten wie “LOCALSTORAGE SAVE Array”

Fragen ähnlich wie “LOCALSTORAGE SAVE Array”

Weitere verwandte Antworten zu “LOCALSTORAGE SAVE Array” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen