Home

function: maxBy


maxBy(array: Array, iteratee: function): *

This method is like `max` except that it accepts `iteratee` which is invoked for each element in `array` to generate the criterion by which the value is ranked. The iteratee is invoked with one argument: (value).

Example(s):

const objects = [{ 'n': 1 }, { 'n': 2 }]

maxBy(objects, ({ n }) => n)
// => { 'n': 2 }

Params:

Name Type Attribute Description
array The array to iterate over.
iteratee The iteratee invoked per element.

Returns:

*

  {
    "comment": "/**\r\n * This method is like `max` except that it accepts `iteratee` which is\r\n * invoked for each element in `array` to generate the criterion by which\r\n * the value is ranked. The iteratee is invoked with one argument: (value).\r\n *\r\n * @since 4.0.0\r\n * @category Math\r\n * @param {Array} array The array to iterate over.\r\n * @param {Function} iteratee The iteratee invoked per element.\r\n * @returns {*} Returns the maximum value.\r\n * @example\r\n *\r\n * const objects = [{ 'n': 1 }, { 'n': 2 }]\r\n *\r\n * maxBy(objects, ({ n }) => n)\r\n * // => { 'n': 2 }\r\n */",
    "meta": {
        "range": [
            596,
            1070
        ],
        "filename": "maxBy.js",
        "lineno": 20,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100005963",
            "name": "maxBy",
            "type": "FunctionDeclaration",
            "paramnames": [
                "array",
                "iteratee"
            ]
        },
        "vars": {
            "result": "maxBy~result",
            "index": "maxBy~index",
            "length": "maxBy~length",
            "computed": "maxBy~computed",
            "value": "maxBy~value",
            "current": "maxBy~current"
        }
    },
    "description": "This method is like `max` except that it accepts `iteratee` which is\rinvoked for each element in `array` to generate the criterion by which\rthe value is ranked. The iteratee is invoked with one argument: (value).",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Math",
            "value": "Math"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Array"
                ]
            },
            "description": "The array to iterate over.",
            "name": "array"
        },
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The iteratee invoked per element.",
            "name": "iteratee"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "*"
                ]
            },
            "description": "Returns the maximum value."
        }
    ],
    "examples": [
        "const objects = [{ 'n': 1 }, { 'n': 2 }]\r\rmaxBy(objects, ({ n }) => n)\r// => { 'n': 2 }"
    ],
    "name": "maxBy",
    "longname": "maxBy",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000555",
    "___s": true,
    "filepath": "maxBy.js"
}