0

I'm trying to pull specific values from a list in localStorage. Here's an example:

Key: Boise, ID, Value: ["43.616","-116.202","Boise, ID"]

I need to split the three values out, but the problem is, I can't use

var storedLocationsArray = value.split(',');

because I need "Boise, ID" to remain as an intact string. "ID" is not a 4th value. Another issue I'm having is if I just console.log():

latitude = storedLocationsArray[0];

I get this: Lat: ["43.616". I can use .replace() functions to get rid of the quotes and brackets, but I still have the problem of the third value being split into two values if there is a comma.

Bill Hambone
  • 157
  • 2
  • 14

1 Answers1

0

I was right localStorage only supports strings. Found the answer here and it works: How do I store an array in localStorage?

key = localStorage.key(i);

var value = JSON.parse(localStorage.getItem(key));
lat = value[0];
Bill Hambone
  • 157
  • 2
  • 14