I am trying to create a function that generates a table using if
and indexOf
within a forEach
loop. I want the table to only display if the input value matches the first item in an array with the name "germany". Can anyone help me figure out what I'm doing wrong?
function showCountriesList(resp) {
var url = 'https://restcountries.eu/rest/v2/name/';
var createdTable = createNewTable();
var countryName = $('#country-name').val();
resp.forEach(function(item) {
var row = document.createElement('tr');
row.innerHTML = `
<td><img style="width: 60px; height: 60px; object-fit: cover" src=${item.flag}></img></td>
<td>${item.name}</td>
<td>${item.capital}</td>
<td>${item.alpha2Code}</td>
<td>${item.timezones}</td>
`;
if (countryName === url.indexOf([item.name])) {
createdTable.appendChild(row); }
});
}