-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind.js
More file actions
32 lines (28 loc) · 762 Bytes
/
Copy pathfind.js
File metadata and controls
32 lines (28 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const arr = [
{
name: 'Lek',
age: 31
},
{
name: 'Ranju',
age: 31
}
]
// console.log(arr)
let searchResult = arr.find((item, index) => {
return item.name === 'Ranju'
})
if(searchResult) {
console.log(searchResult.name, searchResult.age)
} else {
console.log('Not found')
}
/*
* ---------------------------------------------------------------
* The find() method returns the value of the first element that passes a test.
* The find() method executes a function for each array element.
* The find() method returns undefined if no elements are found.
* The find() method does not execute the function for empty elements.
* The find() method does not change the original array.
* ------------------------------------------------------------------
*/