Skip to content
Advertisement

Chosing one Element out of a paragraph with api

i’m experimenting with api’s and now tried to display the capital and borders of a country with this api on a card. This worked.

Now i want to add a function so if you click on one of the borderneighbors it opens their card.

For example i’m on germany now and on neighbors there is written : AUT,BEL,CZE,DNK,FRA,LUX,NLD,POL,CHE

If i click on Pol , i want it to open the card of Poland and show the same informations of Poland. So i made another function where i tried to get the alphaCode of the border countries when i click on them.

I console logged that and saw it’s always giving me AUT,BEL,CZE,DNK,FRA,LUX,NLD,POL,CHE when i click on only one country. So i wanted to know how I can make it only choose one country instead of all.

JavaScript

Advertisement

Answer

borders is an array. You can add a button or link for each element in the array.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement