loading...

re: 15 must-know JavaScript array methods in 2020 VIEW POST

TOP OF THREAD FULL DISCUSSION
re: There is one issue with the 2nd example used in the flatmap. The .flat() call at the end isn't needed, if you run the following code you will see t...
 

There is no issue with that code. It's just two examples.
The first is used with flatMap()

const myAwesomeArray = [[1], [2], [3], [4], [5]]

myAwesomeArray.flatMap(arr => arr * 10)
//-------> Output : [10, 20, 30, 40, 50]

And the second uses flat() and map().

const myAwesomeArray = [[1], [2], [3], [4], [5]]

// With .map() and .flat()
myAwesomeArray.map(arr => arr * 10).flat()
//-------> Output : [10, 20, 30, 40, 50]

As a side note, with flatMap(), the map() function is applied first and flat() comes after.

code of conduct - report abuse