I am using swapi api to get starwars planet data
this is the code:
var data = [];
let url = 'https://swapi.boom.dev/api/planets/';
for (let i = 0; i < 10; i++){
let fetched = fetch(url).then(response => response.json())
.then(json => json.results)
.then(results => data.push(results[i].name))
}
when i run console.log(data)
it returns this array:
now when i try to use its data and run console.log(data[0])
it returns undefined
what shoud i do?