This is what I came up with:
function getKMMacroAndGroupByMacroUUID(macroUUID, plist) {
var _result = undefined;
plist.find(function(group) {
var macros = group.macros;
if (!macros) {
return false;
}
var macro = macros.find(function(m) {
return m.uid === macroUUID;
});
if (macro) {
_result = { macro: macro, group: group };
return true;
}
return false;
});
return _result;
}
Using “find” allows me to exit the iteration loops immediately if I get a hit. Using a result variable in the outer scope allows the result to be accessible after the loops exit.
Is there a better way? This doesn’t smell too awful.