0

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.

3
  • well to be honest i am a noob, so i can have it wrong ;) Commented Jul 1, 2012 at 1:47
  • 1
    Can you show us what have you tried, the code that you wrote that is not working and what you mean by "not working"? Commented Jul 1, 2012 at 1:47
  • i have included the code that i have used Commented Jul 1, 2012 at 1:54

1 Answer 1

5

You have duplicate keys in your object. Use an array instead.

var widgets = [
    {"title": "blablabla", "color": "yellow"},
    {"title": "lorem ipsum", "color": "black"}
]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.