I know I can pass a function that looks like this to the array method .map()
:
var cities = ["rome", "san francisco", "tokyo"];
var cityLen = cities.map(x => x.length);
console.log(cityLen)
// OUTPUT: [4, 13, 5]
I'm passing a single parameter (x
) to the anonymous function in map
where x
gets progressively assigned to each of the elements of cities
.
In the code below have been passed two parameters (d
and i
) to the anonymous function.
function numberRange (start, end) {
return new Array(end - start).fill().map((d, i) => i + start);
}
numberRange(10, 20)
// OUTPUT [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
What are the parameters d
and i
inside the anonymous function and how do they get assigned? How do multiple parameters functions work with .map()
?