您可以在Google脚本中将标签添加到array.forEach吗?

时间:2018-09-14 22:25:58

标签: javascript loops google-apps-script anonymous-function

我想使用array.forEach(遍历数组中的所有元素,并根据元素的值中断或继续迭代。但是,Google Scripts编译器说我需要在每个breakcontinue上贴上标签。可以在以下要点中做到吗?

for( i in traces ){
  environment = null;
  traces[i].servers.forEach( function(server){
    if( server.environment=="DEVELOPMENT" )
      environment = "DEVELOPMENT";
      break;  // got the earliest environment so no reason to keep on looking
    }
    if( server.environment=="QA" )
      environment = "QA";
      continue; // might get DEVELOPMENT next time
    }
    if( server.environment=="PRODUCTION" )
      environment = "PRODUCTION";
      continue; // might get DEVELOPMENT or QA next time
    }        
  });
  . . .
}

或者,我该如何做得更好呢?

0 个答案:

没有答案