I get a warning "value is not returned all the way through" for jQuery.grep in javascript
I am using the following line of code
var selectedMedId = jQuery.grep(privateVariables.medIdData, function (n) {
if (n.DescriptionWithCode.toString().toUpperCase() === description.toString().toUpperCase()) {
return n;
}
});
I have tried also and
var selectedMedId = jQuery.grep(privateVariables.medIdData, function (n) {
return n.DescriptionWithCode.toString().toUpperCase() === description.toString().toUpperCase();
}
});
And I want to get rid of this warning.
+3
source to share
1 answer
If you're looking for a single identifier here, it should be the correct syntax:
var selectedMedId = jQuery.grep(privateVariables.medIdData, function (n) {
return (n.DescriptionWithCode.toString().toUpperCase() === description.toString().toUpperCase());
})[0];
if (selectedMedId) {
...
}
It looks like your first attempt was to return an object, not true
or false
, and your second attempt had too many closing parentheses.
The clue was in the warning, the first attempt didn't always return from $ .grep, it only returned if there was a match in n.DescriptionWithCode and description.
0
source to share