Is it possible to determine if a specific value is present in an array of objects?
I've tried a method, but it always returns false. What would be the most effective way to solve this issue?
My approach:
var dog_database = [
{"dog_name": "Joey", "chip_id": "001", "breed": "mixed"},
{"dog_name": "Max", "chip_id": "002", "breed": "beagle"},
{"dog_name": "Izzy", "chip_id": "003", "breed": "mixed"},
{"dog_name": "Frankie", "chip_id": "004", "breed": "terrier"},
{"dog_name": "Star", "chip_id": "005", "breed": "husky"},
{"dog_name": "Goku", "chip_id": "006", "breed": "lab"}
];
wanted_value = "mixed";
var isPresent = Object.keys(dog_database).some(function(k) {
return Object.keys(dog_database[k]).some(function(i) {
if (dog_database[k][i] == wanted_value) {
return true;
} else {
return false;
}
});
});
console.log(isPresent);