how to save array in local storage js

Solutions on MaxInterview for how to save array in local storage js by the best coders in the world

showing results for - "how to save array in local storage js"
Giada
18 Jun 2019
1// our array
2var movies = ["Reservoir Dogs", "Pulp Fiction", "Jackie Brown", 
3"Kill Bill", "Death Proof", "Inglourious Basterds"];
4 
5// storing our array as a string
6localStorage.setItem("quentinTarantino", JSON.stringify(movies));
7 
8// retrieving our data and converting it back into an array
9var retrievedData = localStorage.getItem("quentinTarantino");
10var movies2 = JSON.parse(retrievedData);
11 
12//making sure it still is an array
13alert(movies2.length);