File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ // return new array
2
+ //not change size of original array
3
+ //uses values from original array when making new one
4
+
5
+ const people = [
6
+ { name : 'bobo' , born : 1987 , position : 'developer' } ,
7
+ { name : 'peter' , born : 1989 , position : 'designer' } ,
8
+ { name : 'sussy' , born : 1975 , position : 'the boss' } ,
9
+ { name : 'Jane' , born : 1999 , position : 'the boss' } ,
10
+ ] ;
11
+
12
+ // const born = people.map(function () {});
13
+ // console.log(ages);
14
+ /*output:
15
+ [ undefined, undefined, undefined ]
16
+ */
17
+
18
+ const borns = people . map ( function ( item ) {
19
+ return `The member company is ${ item . person } as ${ item . position } ` ;
20
+ } ) ;
21
+ console . log ( borns ) ;
22
+
23
+ // example again use return as objects
24
+ const names = people . map ( function ( item ) {
25
+ //create obj firstName and age
26
+ return {
27
+ firstName : item . name ,
28
+ age : 2020 - item . born ,
29
+ } ;
30
+ } ) ;
31
+
32
+ console . log ( names ) ;
You can’t perform that action at this time.
0 commit comments