find item 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: js find element in array by property
var result = jsObjects.find(obj => {
return obj.b === 6
})
Example 3: javascript array.find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);