{"name":"selectMax","title":"selectMax","type":"command","url":"https://community.bistudio.com/wiki/selectMax","revid":379373,"updated":"2026-10-30T23:57:52Z","groups":["Arrays"],"status":"ok","games":{"arma3":"1.66"},"since":"arma3 1.66","arma3_since":"1.66","description":"Returns the array element with maximum numerical value. Engine solution to BIS_fnc_greatestNum and BIS_fnc_findExtreme. Therefore it is expected that supplied array consists of Numbers only. Booleans however are also supported and will be evaluated as Numbers: true - 1, false - 0. nil value treated as 0.\n\n> [!WARNING]\n> Other non Number elements (not recommended) will be evaluated as 0 and **Bad conversion: scalar** message will be logged into .rpt.","syntaxes":[{"syntax":"selectMax array","params":[{"name":"array","type":"Array of Numbers","type_expr":"Array<Number>"}],"returns":{"type":"Number","type_expr":"Number","description":"element with maximum numerical value"},"form":"unary","right":{"text":"array"}}],"examples":[{"code":["_max = selectMax [1,2,3,4,5]; //5"]},{"text":"```sqf\n// Same as, for example:\n_max = _a max _b max _c max _d;\n// Only faster:\n_max = selectMax [_a,_b,_c,_d];\n```","code":["// Same as, for example: \n_max = _a max _b max _c max _d;\n// Only faster:\n_max = selectMax [_a,_b,_c,_d];"]}],"see_also":["selectMin","min","max","selectRandom","select","selectRandomWeighted"],"notes":[{"user":"Longbow","date":"2016-12-19T02:05:00Z","text":"Returns either number or boolean value, in case max value in array 0, command will return either 0 or false, which ever comes first.\nSame for 1 and true values.\n\n```sqf\nselectMax [false,0] // returns false\nselectMax [0,false] // returns 0\nselectMax [true,1] // returns true\nselectMax [1,true] // returns 1\n```\n\nin case all values are equal or less than zero, command may also return other type of values\n\n```sqf\nselectMax [\"\",false,0,-1] // returns \"\"\n```\n\nif nil value appears in array, other values are equal or less than zero, command returns nil"}]}