Accessing Wikipedia API elements


#1

here’s my codepen

I’m trying to access “extract” of one of the objects, then to access them all through a for loop
as I don’t want to address the object by its name, I tried to use the brackets to access extract for object 0 but it returned undefined

example for the json data I’m talking about


#2

If you add &formatversion=2 to your Wikipedia API URL, you will get the results back as an array of objects rather than an object with Page ID properties. It makes it a little more intuitive to loop through and get results based on what we’ve learned here at Free Code Camp.

'https://en.wikipedia.org/w/api.php?action=query&formatversion=2&generator=search&utf8=1&prop=extracts&exintro=1&origin=*&exlimit=20&exchars=200&format=json&gsrsearch=' + search

From looking at your CodePen, it seems you’ve figured out that a for…in loop works great regardless.


#3

yeah, luckily I discovered this for in loop which was new to me, very handy.

I think I’m done with the project except for one issue that’s bothering me, the left side border on the results is not taking the full length, I’ve tried setting the border radius to 0 but I’m still having that issue


#4

Add border-width: 0 to your .result class and it should fix that for you:

.result{
  color: #333;
  text-align:left;
  margin: 6px 10px;
  padding: 3px 15px;
  font-family: 'Raleway', sans-serif;
  border-width: 0;  
  border-left: 6px solid #548464;
}

#5

so it was a pesky almost invisible border causing this, that worked, thank you!