Answers for "how to find a value in an array"

29

find element in array javascript

const simpleArray = [3, 5, 7, 15];
const objectArray = [{ name: 'John' }, { name: 'Emma' }]

console.log( simpleArray.find(e => e === 7) )
// expected output 7

console.log( simpleArray.find(e => e === 10) )
// expected output undefined

console.log( objectArray.find(e => e.name === 'John') )
// expected output { name: 'John' }
Posted by: Guest on July-06-2020
13

javascript find object by property in array

// To find a specific object in an array of objects
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Posted by: Guest on April-20-2020
1

find number in array js

array.include(numberWhichYouWantToFInd);
// if present it will return true otherwise false
Posted by: Guest on February-04-2021

Code answers related to "how to find a value in an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language