如何修改此代碼,以便我可以獲取field.DependencyFieldEvaluated值,並在獲取此值後立即離開函數?獲取返回值並退出forEach在JavaScript中?
function discoverDependentFields(fields) {
fields.forEach(function (field) {
if (field.DependencyField) {
var foundFields = fields.filter(function (fieldToFind) { return fieldToFind.Name === field.DependencyField; });
if (foundFields.length === 1) {
return field.DependencyFieldEvaluated = foundFields[0];
}
}
});
}
什麼錯誤上述功能? – egig
爲什麼不使用'for'循環代替'forEach'函數? – tdragon
你不能擺脫forEach(),嘗試使用'every'來代替http://stackoverflow.com/questions/6260756/how-to-stop-javascript-foreach – gurvinder372