Await in a for loop

function,es6,async,tipjs

How to Await in a for loop

const forLoop = async _ => {
  console.log('Start')

  for (let index = 0; index < fruitsToGet.length; index++) {
    const fruit = fruitsToGet[index]
    const numFruit = await getNumFruit(fruit)
    console.log(numFruit)
  }

  console.log('End')
}
//Use:
'Start'
'Apple: 27'
'Grape: 0'
'Pear: 14'
'End'

Có thể bạn đã miss một số snippets code

How to reverse an Array?

Reversing an array in JS is really simple with the standard array method. Like below

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

promise in javascript

promise in javascript

Remove array of objects from another array of objects

Remove array of objects from another array of objects

Await in a for loop

How to Await in a for loop