My question is about the map method of arrays in JavaScript.
map
You can pass it a function that takes a second argument, the index of the current element of th
Sometimes the index of the element matters. For example, this map replaces every second element with 0:
var a = [1, 2, 3, 4, 5, 6]; var b = a.map(function(el, index) { return index % 2 ? 0 : el; }); console.log(b);
Output:
[1, 0, 3, 0, 5, 0]