How To Use Math.max And Max.min Functions In An Array?
I tried this method in an array to get min and max values but it doesn't work. var array = [3, 6, 1, 5, 0, -2, 3]; var min = Math.min( array ); var max = Math.max( array ); docum
Solution 1:
Use Function.apply
min = Math.min.apply(null, array);min = Math.max.apply(null, array);
apply
is very similar tocall()
, except for the type of arguments it supports. You can use an arguments array instead of a named set of parameters. Withapply
, you can use an array literal
Post a Comment for "How To Use Math.max And Max.min Functions In An Array?"