1let arr = [
2 { name:"string 1", value:"this", other: "that" },
3 { name:"string 2", value:"this", other: "that" }
4];
5
6let obj = arr.find(o => o.name === 'string 1');
7
8console.log(obj);
1const found = accesses.find(x => x.Resource === 'Clients');
2console.log(found)
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
1function getByValue2(arr, value) {
2
3 var result = arr.filter(function(o){return o.b == value;} );
4
5 return result? result[0] : null; // or undefined
6
7}
8