Here is a loop that I am working with:
for (var key in criteria) {
var exists = Object.keys(item).some(function(k) {
return item[k] === "Test";
})
}
Initially, this loop functions as expected and returns 15 trues
based on the number of items. However, when I modify it to the following:
for (var key in criteria) {
var myString = item[key];
var exists = Object.keys(item).some(function(k) {
return item[k] === myString;
});
}
Even though I am certain that item[key]
will eventually be equal to "Test" during the loop, the result is not consistent. Instead, it outputs all trues
.
The structure of Criteria object is:
{
habitat_type: "Mangroves",
issue_specific_terms: "Test"
}
Similarly, Item object looks like this:
{
habitat_type: "Streams and rivers",
cci: "Low productivity/loss of agriculture",
intervention_type: "Restoration",
issue_specific_terms: "Test",
country: "United States of America"
}