javascript map arrow function code example

Example 1: implicit return arrow function

// Single-lineconst
implicit = (value) => value;

// Multi-lineconst
implicit = (value) => (
  value
);

Example 2: array map arrow function

materials.map((str) => {
  const {length} = str;
  return length;
});

Example 3: arrow function map js

const exampleArray = ['aa','bbc','ccdd'];
console.log(exampleArray.map(a => a.length));
//Would print out [2,3,4]

Example 4: concise body arrow functions javascript

const plantNeedsWater = day => day === 'Wednesday' ? true : false;

//If only 1 Parameter no () needed
//Single line return is implicit
//Single line no {} needed