Is it possible to stringfy nested JSON arrays when the length of the arrays is not known or dynamic? For example, if the JSON data from the Wikipedia API is nested arrays, is there a way to recursively loop through the arrays and access specific array elements?
Here’s why I’m asking, I’ve hit a bit of a snag on the “Build a Wikipedia Viewer” project. After over coming multiple challenges in figuring out how to get JSON and what URL to use for the API, I finally figured something out which outputs the JSON in nested arrays. Now, I’m at the point where I need to format the results so that it’s listed like a search engine.
I’m thinking I need to perform some recursive loops, but after reviewing the "Iterate Through an Array with a For Loop " challenge and studying various pagination scripts, and much trial and error, it seems I’m missing something between getting the arrays and looping them. I’m thinking the arrays need to be stringified, but the arrays that need to be processed are nested.
Here’s my pen:
WikipediaSearch
As you can see, when you perform a search, the data is displayed, but not like it should be. When you hover over the “Read More…” link, all of the URLs are there.
The results should display as:
Title
Description
Read More Link
NOT:
Title, Title, Title
Desc,Desc,Desc
Read More… (with all URLs in one href anchor)