var employeeList = [
{
"fname":"John" ,
"lname": "Meg" ,
"tel":"345-543" ,
"email":"employee00@example.com",
"id":"000"
},
{
"fname":"Rony" ,
"lname":"Dodge" ,
"tel": "847-544" ,
"email":"employee01@example.com" ,
"id":"001"
},
{
"fname":"Sally" ,
"lname": "Mark" ,
"tel":"735-334" ,
"email":"employee02@example.com" ,
"id":"002"
},
{
"fname":"Jimmy" ,
"lname":"Rock" ,
"tel":"935-550" ,
"email":"employee03@example.com" ,
"id": "003"
},
{
"fname":"Nora" ,
"lname":"Palmer" ,
"tel": "808-354" ,
"email":"employee04@example.com" ,
"id":"004"
},
{
"fname":"Brody" ,
"lname":"Walker" ,
"tel":"954-574" ,
"email":"employee05@example.com",
"id":"005"
},
{
"fname":"Hana" ,
"lname":"Samy" ,
"tel":"984-458" ,
"email":"employee06@example.com" ,
"id":"006"
},
{
"fname":"Pixa" ,
"lname":"Rufly" ,
"tel":"987-495" ,
"email":"employee07@example.com" ,
"id": "007"
},
{
"fname":"Jena" ,
"lname":"Nathan" ,
"tel":"988-743" ,
"email":"employee08@example.com",
"id": "008"
},
{
"fname":"Lucy" ,
"lname":"Daniel" ,
"tel":"903-482" ,
"email":"employee09@example.com" ,
"id":"009"
}
];
function check(empID) {
for ( var i = 0 ; i < employeeList.length ;i++){
if(employeeList[i].id === empID){
return (employeeList[i].fname);
}else if(employeeList[i].id !== empID){
return "Not Found";
}
}
}
I am trying to loop inside an array of objects to check if parameter(empID) value is equal to an available id then it returns the employee name and if not returns not found