-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind.js
More file actions
34 lines (30 loc) · 877 Bytes
/
Copy pathfind.js
File metadata and controls
34 lines (30 loc) · 877 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
33
34
// find()
// What
// - It takes call back function as parameter.
// - It takes element from the given array and find particular value according to the condition. As soon as it finds a value which satisfies the condition it will stop searching.
// - If it is doesn't find the value that are we looking for it will return `undefine` as value.
// Note
// - It will not modify the original array.
// - It will return single value.
// Syntax
const array = ["123", "1234", "12345"];
const answer = array.find((element) => element.length === 4);
console.log(answer);
// Example
// Find user which id number is 3.
const usersDetails = [
{
userId: 1,
userName: "Batman",
},
{
userId: 2,
userName: "Superman",
},
{
userId: 3,
userName: "Flash",
},
];
const answer1 = usersDetails.find((user) => user.userId === 3);
console.log(answer1.userName);