我有点问题。这是代码:
情况一:
var foundRiders = [];
riders.forEach(function(rider){
Rider.findOne({_id: rider}, function(err, foundRider){
if(err){
console.log("program tried to look up rider for the forEach loop finalizing the results, but could not find");
} else {
foundRiders.push(foundRider);
console.log(foundRiders);
}
});
});
Run Code Online (Sandbox Code Playgroud)
情况B
var foundRiders = [];
riders.forEach(function(rider){
Rider.findOne({_id: rider}, function(err, foundRider){
if(err){
console.log("program tried to look up rider for the forEach loop finalizing the results, but could not find");
} else {
foundRiders.push(foundRider);
}
});
});
console.log(foundRiders);
Run Code Online (Sandbox Code Playgroud)
因此,在情况 A 中,当我控制台日志时,我发现 foundRiders 是一个充满对象的数组。在情况 B 中,当我将 …