find something in an array javascript code example
Example 1: find element in array javascript
const simpleArray = [3, 5, 7, 15];
const objectArray = [{ name: 'John' }, { name: 'Emma' }]
console.log( simpleArray.find(e => e === 7) )
console.log( simpleArray.find(e => e === 10) )
console.log( objectArray.find(e => e.name === 'John') )
Example 2: javascript array.find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 3: object find javascript
function isBigEnough(element) {
return element >= 15;
}
[12, 5, 8, 130, 44].find(isBigEnough);
Example 4: find number in array js
array.include(numberWhichYouWantToFInd);