-2

I am following a tutorial in javascript/angular2 and I know it is a novice question, but if someone could please explain what exactly is this piece of code doing. I have read at various places and in the Mozilla docs, but I am still confused about it. I am aware that: map calls a provided callback function once for each element in an array, in order, and constructs a new array from the results,but what exactly is the code doing in this context:

map(e => e.target.value)
Leff
  • 1,968
  • 24
  • 97
  • 201

2 Answers2

1

It's nearly the same as this:

map(function(e) {
    return e.target.value;
});

...it's just using the concise arrow function form instead of a function function. There are other differences between function functions and arrow functions (arrow functions close over this and a couple of other things, function functions don't), but that code isn't using any of them.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

This is using ES2015/ES6 shorthand syntax. To write it out in ES5:

map(function(e) { return e.target.value; })

The function is the callback function, the e is the current element of the array, and the return value of e.target.value will be the value put in the new array.

metame
  • 2,480
  • 1
  • 17
  • 22