Created
August 9, 2020 04:11
-
-
Save landonconover/1b35315ccc33c11eb676ef69206efe64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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