I am trying to return an array of each of the names in the array of objects that satisfy the condition in the if statement. Can you please help me understand why my code is only returning just the first name when the condition is met? My goal is to return an array of all object names that satisfy the condition in the if statement.
function getNamesOfLegalDrivers(people){
for(let i =0; i < examplePeopleArray.length; i++){
if(examplePeopleArray[i].age > 15) {
return examplePeopleArray[i].name
}
}
}
const examplePeopleArray = [
{ name: 'John', age : 14},
{ name : 'Joey', age : 16},
{ name : 'Jane', age: 18}
];
console.log(getNamesOfLegalDrivers(examplePeopleArray))