DEV Community

Charlotte Fereday
Charlotte Fereday

Posted on

Visualising documentation: JavaScript array.flatMap

Alt Text

Today’s function is array.flatMap(), mdn description here.

FlatMap does two things:

  1. map() -> applies the test function to each element of the aray
  2. flat() -> flattens the results, i.e. smooshes together any nested arrays into a new single level 'flat' array.

That's right, it's the same as doing array.map.flat(). So why use it? It's a bit more efficient.

I've done my own version of the docs with sketches together. Here’s the folder for array.flatMap. Check out the readme to see how you can run the examples.

Top comments (0)