Just trying to get more comfortable with nested objects in arrays, and for in loops. Everything works as I expect it to, until I insert an if statement, then I don't get my expected results of an output of true in the console.
I have tried various mixes of dot/bracket notations for access.
const animals = [
{
species: 'Pets',
list: [
'Dog',
'Cat',
'Rabbit',
'Gerbil',
'Turtle',
'Canary'
]
},
{
species: 'Wild',
list: [
'Bear',
'Lion',
'Deer',
'Tiger',
'Cougar',
'Elk',
'Beaver',
'Elephant',
'Rhino'
]
},
{
species: 'Marine',
list: [
'Shark',
'Salmon',
'Squid',
'Octopus',
'Jellyfish'
]
}
];
for(let i = 0; i < animals.length; i++) {
for(let prop in animals[i]) {
console.log(animals[i][prop])
if(animals[i][prop] === 'Shark'){
console.log(true)
}
}
}
I would like to console log true, if the value equals "Shark"