Skip to content

max ​

找到数组中的最大元素,并返回该元素的值。如果数组为空,则返回 null。

函数接受一个数组作为参数,返回数组中的最大元素,并返回该元素的值。如果数组为空,则返回 null。

签名 ​

ts
function max<T>(arr : T[]) : T | null

参数 ​

  • arr(T[]):需要查找最大元素的数组。

返回值 ​

T | null:数组中的最大元素,如果数组为空,则返回 null。

示例 ​

ts
import { max } from '@/uni_modules/kux-toolkit'

console.log(max([1, 2, 3])); // 3
console.log(max(['a', 'b', 'c'])); // 'c'

Released under the MIT License.