Wikipedia viewer, how to go through the json data

Can’t figure out how to go through this json data. I’ve tried to do a for loop but I guess that data is not an array because using index numbers doesn’t work. Also I’ve tried to use the forEach function but no luck their either.

{
“27667”: {
“title”: “Space”,
“extract”: “Space is the boundless three-dimensional extent in which objects and events have relative position and direction.”
},
“28189”: {
“title”: “Space Shuttle”,
“extract”: “The Space Shuttle was a partially reusable low Earth orbital spacecraft system operated by the U.S. National Aeronautics and Space Administration (NASA), as part of the Space Shuttle program.”
},
“28431”: {
“title”: “Space exploration”,
“extract”: “Space exploration is the ongoing discovery and exploration of celestial structures in outer space by means of continuously evolving and growing space technology.”
},
“28434”: {
“title”: “Outline of space science”,
“extract”: “Space science encompasses all of the scientific disciplines involved in space exploration and studying phenomena occurring in outer space, such as space medicine and astrobiology.”
},
“29192”: {
“title”: “Space elevator”,
“extract”: “A space elevator is a proposed type of space transportation system.”
},
“67896”: {
“title”: “Space tourism”,
“extract”: “Space tourism is space travel for recreational, leisure or business purposes.”
},
“113496”: {
“title”: “Space weather”,
“extract”: “Space weather is a branch of space physics and aeronomy concerned with the time varying conditions within the Solar System, including the solar wind, emphasizing the space surrounding the Earth, including conditions in the magnetosphere, ionosphere and thermosphere.”
},
“177602”: {
“title”: “Outer space”,
“extract”: “Outer space, deep space, or just space, is the void that exists between celestial bodies, including Earth.”
},
“2061420”: {
“title”: “Space (disambiguation)”,
“extract”: “Space is a multi-dimensional framework in which we can sense direction and quantify distances between objects or points.”
},
“20598932”: {
“title”: “Hilbert space”,
“extract”: “The mathematical concept of a Hilbert space, named after David Hilbert, generalizes the notion of Euclidean space.”
}
}

have you tried a for…in loop?

I can’t quite remember the data received from the wiki api but it may go something like this:

 for (var i in data.result) console.log(data.result[i])

maybe you need to parse?

that seems promising but I cant get it working.

According to this it looks to me like this for…in is ment for going through the properties inside an object but I have a list of 10 individual objects and need somehow to loop through all of them one by one.

okay, you are almost there :slight_smile: you are still displaying the object, you need to show the items inside the object. try outputting results[i].title and see what happens

hey that worked! thanks a lot. Dont really understand how that works, have to look into it

I just noticed that now the search result are in “wrong” order, this is of course due to the way that for…in goes through the data, do you happen to know if there is a way to change this? top to bottom —> bottom to top