- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38_array_find.js
More file actions
Latest commit
32 lines (27 loc) · 940 Bytes
/
Copy path38_array_find.js
File metadata and controls
32 lines (27 loc) · 940 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
// find
// returns object
// returns first match, if not match undefined
// great for getting unique value
letpeople=[
{id: 1,name: 'john doe',born: 1983,position: 'developer'},
{id: 2,name: 'bobo',born: 1987,position: 'developer'},
{id: 3,name: 'peter',born: 1989,position: 'designer'},
{id: 1,name: 'sussy',born: 1975,position: 'the boss'},
{id: 1,name: 'Jane',born: 1999,position: 'the boss'},
];
constiDs=people.find(function(iDs){
// here first match will print but if u use filter will print all obj with id:1
returniDs.id===5||iDs.position==='developer';
});
console.log(iDs);
// example again
constshpMember=['lutfi','Zoro','Sanji'];
console.log(
shpMember.filter(function(items){
returnitems==='Zoro';
})
);
/*
and output will result lutfi for the first match, cause use find.. but if use map, filter will result as array
[ 'lutfi', 'Zoro', 'Sanji' ]
*/