Skip to content

Instantly share code, notes, and snippets.

@gil00pita
Forked from gisderdube/forOf.js
Last active February 8, 2019 23:13
Show Gist options
  • Save gil00pita/19bebb36672a11de025a057088956f10 to your computer and use it in GitHub Desktop.
Save gil00pita/19bebb36672a11de025a057088956f10 to your computer and use it in GitHub Desktop.
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a Often times, it is necessary to fetch multiple datasets and do something for each of those or complete a task after all of the async calls have returned
import axios from 'axios'
let myData = [{id: 0}, {id: 1}, {id: 2}, {id: 3}]
async function fetchData(dataSet) {
for(entry of dataSet) {
const result = await axios.get(`https://ironhack-pokeapi.herokuapp.com/pokemon/${entry.id}`)
const newData = result.data
updateData(newData)
console.log(myData)
}
}
function updateData(newData) {
myData = myData.map(el => {
if(el.id === newData.id) return newData
return el
})
}
fetchData(myData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment