Skip to content

Commit 4d5cc75

Browse files
committed
array filter
1 parent 0cbc16e commit 4d5cc75

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

37_array_filter.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// filter
2+
// return new array
3+
// can manipulate the size of new array
4+
// return based on condition
5+
6+
let people = [
7+
{ name: 'john doe', born: 1983, position: 'senior developer' },
8+
{ name: 'bobo', born: 1987, position: 'developer' },
9+
{ name: 'peter', born: 1989, position: 'designer' },
10+
{ name: 'sussy', born: 1975, position: 'the boss' },
11+
{ name: 'Jane', born: 1999, position: 'the boss' },
12+
];
13+
14+
const developer = people.filter(function (items) {
15+
return (
16+
items.position === 'developer' || items.position === 'senior developer'
17+
);
18+
});
19+
20+
console.log(developer);
21+
22+
const ages = people.filter(function (items) {
23+
// yg kurang dari 1989 ada 3
24+
return items.born < 1989;
25+
});
26+
console.log(ages);

0 commit comments

Comments
 (0)