首页 > 解决方案 > forEach 循环未正确循环

问题描述

我有以下代码:

array.forEach(function(x){
  console.log("inside foreach")

  const getData = async () => {
  try {
   const jsonValue = await AsyncStorage.getItem("item")
   if(jsonValue != null){

   console.log("not null")

   }else{

   console.log("null")

   }
   }
   getData()
})

它不能正常工作,输出首先检索所有“内部 foreach”,然后检索其余部分。我该如何解决?谢谢!

标签: javascriptloopsasynchronousforeachasyncstorage

解决方案


推荐阅读