what are the most efficient ways to return a value from a loop?

what are the most efficient ways to return a value from a loop?


What are the most efficient ways to return a value from a loop? FlowId in the following example represents a concatenation of region names followed by "Flow". For example, "NortheastSoutheastFlow", "TexasSoutheastFlow", etc. regionNames represents an array of region names stored as a global variable like ['Northeast','Southeast','Texas']. The regionName function param represents a known region name and the goal of the function is return the other region name included in the flow:

function getOtherFlowRegionName(flowId, regionName) { regionNames.forEach(function(otherRegionName) { if(flowId.indexOf(otherRegionName) > -1) return otherRegionName; }); }