I have a function defined like this:
var getPhoneNumber = function (list, phoneType) {
if (_.isEmpty(list)) {
return "Not Entered"
};
_.each(list, function(phoneNo){
if (phoneNo.name === phoneType) {
return phoneNo.value;
};
});
return "Not Entered";
}
list
is an Array
, while phoneType
is a String
. The problem is the function always returns the value Not Entered
even if the list
is not empty and has a phoneNo.name
equal to phoneType
. If I add a console.log
in the if
it shows that the condition is true and prints the console.log
message but still returns Not Entered
Aucun commentaire:
Enregistrer un commentaire