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

group by property javascript use reduce

group by property javascript use reduce

How to use the spread operator to flatten array of objects in javascript

How to use the spread operator to flatten array of objects in javascript

10 mẹo sử dụng array và object trong javascript

10 mẹo sử dụng array và object trong javascript

Sử dụng reduce và concat làm phẳng một array

Array.reduce() và Array.concat() có thể giúp chúng ta làm phẳng một Array như:

jQuery on hover

Jquery on mouse over example.