Home

function: flatMap


flatMap(collection: Array, Object, iteratee: function): Array

Creates a flattened array of values by running each element in `collection` thru `iteratee` and flattening the mapped results. The iteratee is invoked with three arguments: (value, index|key, collection).

Example(s):

function duplicate(n) {
  return [n, n]
}

flatMap([1, 2], duplicate)
// => [1, 1, 2, 2]

Params:

Name Type Attribute Description
collection The collection to iterate over.
iteratee The function invoked per iteration.

Returns:

Array

  {
    "comment": "/**\r\n * Creates a flattened array of values by running each element in `collection`\r\n * thru `iteratee` and flattening the mapped results. The iteratee is invoked\r\n * with three arguments: (value, index|key, collection).\r\n *\r\n * @since 4.0.0\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Function} iteratee The function invoked per iteration.\r\n * @returns {Array} Returns the new flattened array.\r\n * @see flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues\r\n * @example\r\n *\r\n * function duplicate(n) {\r\n *   return [n, n]\r\n * }\r\n *\r\n * flatMap([1, 2], duplicate)\r\n * // => [1, 1, 2, 2]\r\n */",
    "meta": {
        "range": [
            772,
            867
        ],
        "filename": "flatMap.js",
        "lineno": 24,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100002552",
            "name": "flatMap",
            "type": "FunctionDeclaration",
            "paramnames": [
                "collection",
                "iteratee"
            ]
        }
    },
    "description": "Creates a flattened array of values by running each element in `collection`\rthru `iteratee` and flattening the mapped results. The iteratee is invoked\rwith three arguments: (value, index|key, collection).",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Collection",
            "value": "Collection"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Array",
                    "Object"
                ]
            },
            "description": "The collection to iterate over.",
            "name": "collection"
        },
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The function invoked per iteration.",
            "name": "iteratee"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "Array"
                ]
            },
            "description": "Returns the new flattened array."
        }
    ],
    "see": [
        "flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues"
    ],
    "examples": [
        "function duplicate(n) {\r  return [n, n]\r}\r\rflatMap([1, 2], duplicate)\r// => [1, 1, 2, 2]"
    ],
    "name": "flatMap",
    "longname": "flatMap",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000277",
    "___s": true,
    "filepath": "flatMap.js"
}