map elements of an array then make an action

Solutions on MaxInterview for map elements of an array then make an action by the best coders in the world

showing results for - "map elements of an array then make an action"
Sara
31 Sep 2017
1let numbers = [1, 2, 3, 4]
2let filteredNumbers = numbers.map(function(num, index) {
3  if (index < 3) {
4     return num
5  }
6})
7// index goes from 0, so the filterNumbers are 1,2,3 and undefined.
8// filteredNumbers is [1, 2, 3, undefined]
9// numbers is still [1, 2, 3, 4]
10
11