-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharr_maps.js
28 lines (22 loc) · 904 Bytes
/
arr_maps.js
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
/*
ITERATE OVER ARRAYS WITH MAP
The map method is a convenient way to iterate through arrays.
Here's an example usage:
var timesFour = oldArray.map(function(val){
return val * 4;
});
The map method will iterate through every element of the array, creating a new
array with values that have been modified by the callback function, and return it.
Note that it does not modify the original array.
In our example the callback only uses the value of the array element (the val
argument) but your callback can also include arguments for the index and array being
acted on.
Use the map function to add 3 to every value in the variable oldArray, and save the
results into variable newArray. oldArray should not change.
*/
var oldArray = [1,2,3,4,5];
// Only change code below this line.
var newArray = oldArray.map(function (val) {
return val + 3;
});
console.log("What is newArray: ", newArray);