I'm currently working on a project that involves utilizing the swapi co API. Although I've successfully fetched results from the website, I'm struggling with displaying only specific API objects, particularly array spaceships.
var linkApi="https://swapi.co/api/starships"
async function starships()
{
let response = await fetch(linkApi);
let data = await response.json()
for(i=0; i<data.results.length;i++){
return{
"count": data.count,
"results":[
{
"name":data.results[i].name,
"model": data.results[i].model,
"crew":data.results[i].crew,
}
]
}
}
}
starships()
.then(data => console.log(data));
This is the desired format:
{
"count": "",
"results": [
{
"name": "",
"model": "",
"crew": "",
"passengers": "",
"films_count": "",
"films": [
{
"title": "",
"director": "",
"release_date": ""
}
]
}
]
}