A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-flatmapdeep-method/ below:

Lodash _.flatMapDeep() Method - GeeksforGeeks

Lodash _.flatMapDeep() Method

Last Updated : 15 Jul, 2025

Lodash _.flatMapDeep() method creates a flattened array of values by running each element in the given collection through the iteratee function and recursively flattens the mapped results. It is similar to the _.flatMap() method.

Syntax:
_.flatMapDeep(collection, iteratee);
Parameters: Return Value:

This method returns the new flattened array.

Example 1: In this example, we are using the _.flatMapDeep() method for duplicating the elements of a given array.

javascript
// Requiring the lodash library 
const _ = require("lodash");

// Original array 
let users = (['aaa', 'bbb', 'ccc',
    'ddd', 'eee', 'fff']);

// Using the _.flatMapDeep() method
let flat_map =
    _.flatMapDeep(users,
        function duplicate(n) {
            return [[[n, n]]];
        }
    )

// Printing the output 
console.log(flat_map);

Output:

[
'aaa', 'aaa', 'bbb', 'bbb',
'ccc', 'ccc', 'ddd', 'ddd',
'eee', 'eee'
]

Example 2: In this example, we are using the _.flatMapDeep() method for naking apatter of a given array.

javascript
// Requiring the lodash library 
const _ = require("lodash");

// Original array 
let user1 = ([1, 2, 3, 4, 5, 6, 7]);
let user2 = (['a', 'b', 'c', 'd', 'e']);

// Using the _.flatMapDeep() method
let flat_map1 =
    _.flatMapDeep(user1,
        function makePattern(n) {
            return [[[n, n + ">"]]];
        }
    )

let flat_map2 =
    _.flatMapDeep(user2,
        function makePattern(n) {
            return [[["<" + n, n]]];
        }
    )

// Printing the output 
console.log(flat_map1);
console.log(flat_map2);

Output:

[
1, '1>', 2, '2>',
3, '3>', 4, '4>',
5, '5>', 6, '6>',
7, '7>'
]
[
'<a', 'a', '<b',
'b', '<c', 'c',
'<d', 'd', '<e',
'e'
]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4