title: Find the Max Value in an array using JavaScript function
body: <p>I have this function, the purpose is to find the maximum (number) element in an array, the value is coming from an argument. Can you please explain what is going on line by line with the code below.</p>
  <pre><code>function max(arr){
   var max = arr[0];
   for(var i=1; i&lt;arr.length; i++){
     if(arr[i] &gt; max){
       max = arr[i];   
     }
    }
  return max;
  }
  
  max([4,12,3,8,0,22,56]); //output is 56
  </code></pre>