find object in array typescript code example
Example 1: array find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
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: typescript array find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);