Javascript Data Type How to - Find min and max time in a set of arrays








Question

We would like to know how to find min and max time in a set of arrays.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
var arr= ["17:30:48","19:30:48","17:30:48","19:30:48","17:30:48","19:30:48","17:30:48","19:30:48","17:30:48","19:30:48","17:30:48","19:30:48"];
arr.sort(function (a,b) {<!--from  ww w.  j  a  v  a2  s .c o  m-->
    if(a > b) { return -1; }
    if(a < b) { return 1; }    
    return 0;
});
document.writeln(arr[0]);
document.writeln(arr[arr.length - 1]);
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: