Created
October 30, 2017 19:42
-
-
Save SastraNababan/fa78c3c54604ee103f37a04b810e062f to your computer and use it in GitHub Desktop.
Promise in Looping Example
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
const doFetch = (url) => fetch(url).then(result => result.json()) | |
let urls =[ | |
'https://jsonplaceholder.typicode.com/posts/1', | |
'https://jsonplaceholder.typicode.com/posts/2', | |
'https://jsonplaceholder.typicode.com/posts/3', | |
'https://jsonplaceholder.typicode.com/posts/4', | |
] | |
let promises=[] | |
urls.map((url) => { | |
promises.push(doFetch(url)) | |
}) | |
Promise.all(promises) | |
.then(results => console.log(results)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment