Reputation: 28074
I'm just reading up on ES6 features that have been implemented in Node v4.0.0 and saw Arrows. The example from Arrow Functions is:
var a = [
"Hydrogen",
"Helium",
"Lithium",
"Beryllium"
];
var a2 = a.map(function(s){ return s.length });
var a3 = a.map( s => s.length );
My question is how can I include multiple lines of code inside of a.map( s => s.length );
rather than just returning the length as in this example.
Upvotes: 2
Views: 111
Reputation: 3026
Just wrap your multiple code lines in curly braces like this:
var a3 = a.map( s => {
var temp = s.length;
return temp;
});
Upvotes: 8