find arrays code example
Example 1: js find value in array
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 2: js array find
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
ages.find(checkAdult);
Example 3: find typescript
const inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
function findCherries(fruit) {
return fruit.name === 'cherries';
}
inventory.find(findCherries);
inventory.filter(x => x.name === 'bananas')[0];
inventory.find(e => e.name === 'apples');
Example 4: find all of array which satisfy condition javascript
myArray.filter(x => x > 5)