我想使用array.forEach(
遍历数组中的所有元素,并根据元素的值中断或继续迭代。但是,Google Scripts编译器说我需要在每个break
或continue
上贴上标签。可以在以下要点中做到吗?
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
}
});
. . .
}
或者,我该如何做得更好呢?