Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript find the second highest Element from array

var secondMax = function (){ 
    var arr = [20, 120, 111, 215, 54, 78]; // use int arrays
    var max = Math.max.apply(null, arr); // get the max of the array
    arr.splice(arr.indexOf(max), 1); // remove max from the array
    return Math.max.apply(null, arr); // get the 2nd max
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #find #highest #Element #array
ADD COMMENT
Topic
Name
1+4 =