STEEL STEEL -4 years ago 121
Javascript Question

Find smallest value in Array without Math.min

How can I find the lowest number in an array without using

Math.min.apply
? I must use a
for-loop
.

var arr = [5,1,9,5,7];

Answer Source

If you must use a for loop:

var arr = [5,1,9,5,7];
var smallest = arr[0];

for(var i=1; i<arr.length; i++){
    if(arr[i] < smallest){
        smallest = arr[i];   
    }
}

console.log(smallest);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download