Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  175] [ 4]  / answers: 1 / hits: 16902  / 13 Years ago, fri, november 11, 2011, 12:00:00

How can I count how many different values I have in 1 localstorage key.



For example:



This is my localstorage:



[{id:item-1,icon:google.com},{id:item-2,icon:youtube.com}]


For this example I'd like an alert of 2 different values. So basically I want to count the {}..



Is that possible?


More From » jquery

 Answers
15

localStorage is an object, so just localStorage.length gives you the number of entries.



However I think I might be misunderstanding you. Do you mean you have one key, and that key's value is a JSON.stringify'd object? If so, you could do JSON.parse(localStorage.keyname).length to unserialise the value and count how many there are in there.


[#89183] Thursday, November 10, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelyn

Total Points: 619
Total Questions: 102
Total Answers: 104

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;