Use a good old vanilla for loop:
function discoverDependentFields(fields) {
for (var fieldIndex = 0; fieldIndex < fields.length; fieldIndex ++) {
var field = fields[fieldIndex];
if (field.DependencyField) {
var foundFields = fields.filter(function(fieldToFind) {
return fieldToFind.Name === field.DependencyField;
});
if (foundFields.length === 1) {
return foundFields[0];
}
}
}
}
Well, if you want to stay fancy, use filter
again:
function discoverDependentFields(fields) {
return fields.filter(function(field) {
if (field.DependencyField) {
var foundFields = fields.filter(function(fieldToFind) {
return fieldToFind.Name === field.DependencyField;
});
if (foundFields.length === 1) {
return foundFields[0];
}
}
})[0];
}