1// MDN Ref:
2// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
3
4var result = jsObjects.find(obj => {
5 return obj.b === 6
6});
1var __POSTS = [
2 { id: 1, title: 'Apple', description: 'Description of post 1' },
3 { id: 2, title: 'Orange', description: 'Description of post 2' },
4 { id: 3, title: 'Guava', description: 'Description of post 3' },
5 { id: 4, title: 'Banana', description: 'Description of post 4' }
6];
7
8var __FOUND = __POSTS.find(function(post, index) {
9 if(post.title == 'Guava')
10 return true;
11});
12
13// On success __FOUND will contain the complete element (an object)
14// On failure it will contain undefined
15console.log(__FOUND); // { id: 3, title: 'Guava', description: 'Description of post 3' }
16