O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting the Minimum Number in a Set

Math.min(8,"0x5",12,"44",8,23,77); //returns 5 var arr1 = [4,8,12,3,7,11]; Math.min.apply( Math, arr1 ); //returns 3 var arr2 = ["0x5",8,12,"4",8,23,77,"0x1F"]; Math.min.apply( Math, arr2 ); //returns 4

The Math.min(item, item, ...) method allows you to find the smallest number in a set. You can also apply an array object to the .min() method using Math.min.apply(Math, array). This returns the smallest number in the array. The array can contain string representations of numbers, such as "4" and "0x5B", but not character strings such as "A". If the array contains character strings, the result will be NaN.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required