at the beginning I want to say that I checked a lot of solutions but none of it was straight accurate to my problem. I wonder if it's possible to fetch data from JSON (name, surname and id). In every of each list will be other data. The issue is length of lists will be as much as JSON's length so it has to be automatically generated, but unfortunately in promises, you are not allowed to make functions so what is the solution for that problem?
const nameList = document.querySelector('.name-list')
const surnameList = document.querySelector('.surname-list')
const idList = document.querySelector('.id-list')
fetch('http://www.json-generator.com/api/json/get/cuSKqtKmgi?indent=2')
.then(response => response.json())
.then(data => {
console.log(data);
});
body{
display: flex;
justify-content: space-around;
}
<body>
<ul class="name-list">
</ul>
<ul class="surname-list">
</ul>
<ul class="id-list">
</ul>
<ul class="example">
<li>Example1</li>
<li>Example2</li>
<li>Example3</li>
<li>Example4</li>
<li>Example5</li>
</ul>
</body>
That is only an exercise but will help me understand fetch more. If something is unclear feel free to ask :)
data(right where youconsole.log) and insert items in the 3 lists.Uncaught (in promise) TypeError: can't access property "forEach", data.person.name is undefinederror that's why I thought you're not allowed to do that, thanks :)