2. Find the second largest element from an array in javascript?

  

        var secondMax = function (arr) {
        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
        };

        var arr = [20, 120, 111, 215, 54, 78]; // use int arrays
        var max2 = secondMax(arr);

        console.log(max2)