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

Promise.all là gì?

Promise.all là gì? Hiểu và sử dụng promise all trong những trường hợp nào trong vòng 1 phút.

Detect when your site is visible to users

Detect when your site is visible to users

Rolling loading

Nguyên tắc là theo dõi các sự kiện cuộn trang và phân tích mối quan hệ thuộc tính giữa clientHeight , scrollTop và scrollHeight .

Lấy tháng hiện tại trong javascript

Lấy tháng hiện tại trong javascript

await axios get

await axios get