File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ // map
2
+ // does return a new array
3
+ // does not change size of original array
4
+ // uses values from original array when making new one
5
+
6
+ const people = [
7
+ { name : 'bob' , age : 20 , position : 'developer' } ,
8
+ { name : 'peter' , age : 25 , position : 'designer' } ,
9
+ { name : 'susy' , age : 30 , position : 'the boss' } ,
10
+ { name : 'anna' , age : 35 , position : 'the boss' } ,
11
+ ] ;
12
+
13
+ const ages = people . map ( function ( person ) {
14
+ return person . age + 20 ;
15
+ } ) ;
16
+ const newPeople = people . map ( function ( person ) {
17
+ return {
18
+ firstName : person . name . toUpperCase ( ) ,
19
+ oldAge : person . age + 20 ,
20
+ } ;
21
+ } ) ;
22
+
23
+ const names = people . map ( function ( person ) {
24
+ return `<h1>${ person . name } </h1>` ;
25
+ } ) ;
26
+
27
+ document . body . innerHTML = names . join ( '' ) ;
28
+
29
+ console . log ( names ) ;
You can’t perform that action at this time.
0 commit comments