![]() |
VOOZH | about |
Lodash _.flatMap() method creates a flattened array of values by running each element in the collection through iterate and flattening the mapped results.
_.flatMap(collection, iteratee);Return Value: This method returns the new flattened array.
Example 1: In this example, we are passing a duplicate function to the lodash _.flatMap() method and an array and getting the result in the console.
Output:
[
35, 35, 47, 47, 58, 58,
69, 69, 94, 94, 13, 13,
72, 72
]
Example 2: In this example, we are passing a duplicate function to the lodash _.flatMap() method and an array and getting the result in the console.
Output:
[
3.5, 3.5, 4.7, 4.7, 5.8, 5.8,
6.9, 6.9, 9.4, 9.4, 1.3, 1.3,
7.2, 7.2
]
[
3, 3, 4, 4, 5, 5,
9, 9, 9, 9, 1, 1,
7, 7
]
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.