I have an array with a list of customers. I am declaring a function that takes a customer name as a parameter. I want this function to loop through the array to find out whether or not the customer is in the array.
var customers = [
{fullName: 'Marshall Hathers',
dob: '01/07/1970'},
{fullName: 'Margaret May',
dob: '01/07/1980'}
];
The function:
function findCustomer(customer) {
for(i=0; i<customers.length; i++) {
var found;
if(customer === customers[i].fullName) {
found = true;
console.log('Customer has been found');
break;
} else {
found = false;
console.log('Customer has not been found');
break;
}
}
It works well the first time a customer is found, but it prints out incorrectly when trying to find the second customer.
Can anyone please assist?