Reputation: 2207
I an trying to loop an javascript object, but i cant get it running. The data is comming form the localStorage.
my output:
{"widget": {"title": "blablabla", "color": "yellow"},"widget": {"title": "lorem ipsum", "color": "black"},......}
// what i have tried(the key works)
var list = JSON.parse(the localStoragekey);
for(var key in list){
if (list.hasOwnProperty(key)){
console.log(list[key])
}
}
I have looked on the web(and Stackoverflow) but i cant seem to find a working solution.
Upvotes: 0
Views: 88
Reputation: 163232
You have duplicate keys in your object. Use an array instead.
var widgets = [
{"title": "blablabla", "color": "yellow"},
{"title": "lorem ipsum", "color": "black"}
]
Upvotes: 5