Get the highest value in an array: - Javascript Array

Javascript examples for Array:sort

Description

Get the highest value in an array:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
var points = [40, 100, 1, 5, 25, 10,5,6,7,8,7,6,4,23];
document.getElementById("demo").innerHTML = points;

function myFunction() {//from  w  ww .j  a v a  2 s . c om
    points.sort(function(a, b){return b-a});
    document.getElementById("demo").innerHTML = points[0];
}
</script>

</body>
</html>

Related Tutorials