max

math

Computes the maximum value of array. If array is empty or falsy, undefined is returned.

Signature

max<T extends number>(array: T[]): T | undefined

Parameters

NameTypeDescription
arrayT[]The array to iterate over

Returns

T | undefined - Returns the maximum value

Examples

Basic usage

import { max } from 'dashlite'

const result = max([4, 2, 8, 6])
console.log(result)

Output:

8

Empty array

import { max } from 'dashlite'

const result = max([])
console.log(result)

Output:

undefined

Available since version 1.0.0