1var myArray = [1,"word",23,-12,"string"];//your list of values, they can be strings or numbers
2
3//SAVING
4function save(a,b,c,d,e) {//the number of parameters you add is how many items you save
5 var itemArray = [a,b,c,d,e];//number of items here must be the same as number of parameters
6 var keyArray = ["one","two","three","four","five"];//must be same length as itemArray
7 for (var i = 0; i < keyArray.length; i++) {
8 if (typeof(itemArray[i]) === "number") {
9 itemArray[i] = "+"+itemArray[i];//leave a reminder that it was a number
10 }
11 if (typeof(itemArray[i]) !== undefined) {
12 localStorage.setItem(keyArray[i],itemArray[i]);//only add a value to the current key if it's not undefined
13 }
14 }
15}
16//to use the function (whenever you want to save):
17save.apply(this, myArray);//assuming that myArray is the array you want to set
18
19//LOADING
20function load() {
21 var list = [];
22 var keyArray = ["one","two","three","four","five"];
23 for (var i = 0; i < keyArray.length; i++) {
24 var item = localStorage.getItem(keyArray[i]);
25 if (item.charAt(0) == "+") {
26 item = parseFloat(item.substring(1));
27 }
28 list.push(item);
29 }
30 return list;
31}
32//to use the function
33myArray = load();//sets your array back to how it was when you saved it