Moving to Arrow Functions
Progressing from the old way of looping through an array toward arrow functions.
Old way
var nums = [1, 2, 3, 4, 5, 6],
dblNums = [];
for (var i = 0, len = nums.length; i < len; i++) {
dblNums[i] = nums[i] * 2;
}
Using the map function1
var nums = [1, 2, 3, 4, 5, 6],
dblNums = nums.map(function(n) {
return n * 2;
});
Using an arrow function2 in the map function
var nums = [1, 2, 3, 4, 5, 6],
dblNums = nums.map(n => n * 2);
Written on July 20, 2016