Created
October 22, 2020 15:28
-
-
Save sillyslux/f94351533fc287d140ec07e6f2233a3b to your computer and use it in GitHub Desktop.
try here https://swapi.dev/ with your browser console
This file contains 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
async function getAll () { | |
let cont = true; | |
let page = 1; | |
let ret = []; | |
while(cont) { | |
const moreShips = await fetch("https://swapi.dev/api/starships/?page="+page).then(r => r.json()); | |
if (!moreShips.next) cont = false; | |
page = page + 1; | |
ret = [...ret, moreShips]; | |
} | |
return ret; | |
} | |
getAll().then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment