我想知道是否有人能解释我为什么这个函数返回undefined而不是创建对象
var people = [
{name: 'John'},
{name: 'Dean'},
{name: 'Jim'}
];
function test(name) {
people.forEach(function(person){
if (person.name === 'John') {
return person;
}
});
}
var john = test('John');
console.log(john);
// returning 'undefined'
Run Code Online (Sandbox Code Playgroud)