title: Flatten multi-level/nested array in javascript
body: <p>I'm trying to understand how this snippet of codes work to flatten multi levels/nested array</p>
  
  <p>can anyone please help to elaborate? thanks</p>
  
  <pre><code>var flatten = function(a, shallow,r){
    if(!r){ r = []}     //what does the exclamation mark mean here?...
  
  if (shallow) {
    return r.concat.apply(r,a);  //I can't find what's .apply for concat method
    }
  
     for(var i=0; i&lt;a.length; i++){
          if(a[i].constructor == Array){
              flatten(a[i],shallow,r);
          }else{
              r.push(a[i]);
          }
      }
      return r;
  }
  
  alert(flatten([1, [2], [3, [[4]]],[5,6]]));
  </code></pre>