const persons = [
{name:"Shirshak",gender:"male"},
{name:"Amelia",gender:"female"},
{name:"Amand",gender:"male"}
]
//filter return all objects in array
let male = persons.filter(function(person){
return person.gender==='male'
})
console.log(male) //[{name:"Shirshak",gender:"male"},{name:"Amand",gender:"male"}]
//find return first object that match condition
let female = persons.find(function(person){
return person.gender==='female'
})
const inventory = [
{id: 23, quantity: 2},
{id: '24', quantity: 0},
{id: 25, quantity: 5}
];
// Check type and value using ===
const result = inventory.find( ({ id }) => id === 23 );
// Check only value using ==
const result = inventory.find( ({ id }) => id == 24 );
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
/* find() runs the input function agenst all array components
till the function returns a value
*/
ages.find(checkAdult);