Skip to content

Instantly share code, notes, and snippets.

@landonconover
Created August 9, 2020 04:11
Show Gist options
  • Save landonconover/1b35315ccc33c11eb676ef69206efe64 to your computer and use it in GitHub Desktop.
Save landonconover/1b35315ccc33c11eb676ef69206efe64 to your computer and use it in GitHub Desktop.
function get30SWPeople(params) {
let people = [];
const SWPromises = [
fetch('https://swapi.dev/api/people/?page=1'),
fetch('https://swapi.dev/api/people/?page=2'),
fetch('https://swapi.dev/api/people/?page=3')
]
return Promise.all(SWPromises)
.then(ResponsesArr => {
return Promise.all(
ResponsesArr.map(data => data.json())
)
})
.then(jsonDataArr => {
people = jsonDataArr.reduce(
(acc, data) => [...acc, ...data.results]
, people)
return people;
})
}
get30SWPeople().then(people => {
console.log(people)
//do stuff with the people here. 😁
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment