javascript search for object in array code example
Example 1: javascript find object in array
myArray.findIndex(x => x.id === '45');
Example 2: javascript find item in array of objects
var __POSTS = [
{ id: 1, title: 'Apple', description: 'Description of post 1' },
{ id: 2, title: 'Orange', description: 'Description of post 2' },
{ id: 3, title: 'Guava', description: 'Description of post 3' },
{ id: 4, title: 'Banana', description: 'Description of post 4' }
];
var __FOUND = __POSTS.find(function(post, index) {
if(post.title == 'Guava')
return true;
});
console.log(__FOUND);
Example 3: find in js
The first element that will be found by that function
const f = array1.find(e => e > 10);