document.querySelector("#enter").addEventListener("click", e => {
e.preventDefault();
var inputValue = searchApi.value;
fetch('https://wft-geo-db.p.rapidapi.com/v1/geo/cities/' +inputValue, options)
.then(response => response.json())
.then(response => {
console.log(response);
return response;
})
.then((data) => {
var title = document.createElement("li")
title.classList.add('list-item');
title.innerText = JSON.stringify(data);
var list = document.getElementById("result-list");
list.appendChild(title);
})
.catch(err => console.error(err));
});
HTML looks like this
<h2 class="justify-center flex">Results</h2>
<ul id="result-list">
<li class="list-item "></li>
</ul>
Because I use JSON stringify it turns out as it did, but I want the data to be displayed one by one and not all in one line. I have tried forEach, and for loop but I don't think I did it correctly, so any help is appreciated.