title: How does the [].push.apply work?
body: <p>can someone please explain me how does this line of code work.</p>
  
  <pre><code>[].push.apply(perms, permutation(arr.slice(0), start + 1, last));
  </code></pre>
  
  <p>This function generates an array of all permutations of an input array;</p>
  
  <pre><code>var permutation = function(arr, start, last){
    var length = arr.length;
  
    if(!start){
      start = 0;
    }
  
    if(!last){
      last = length - 1;
    }
  
    if( last === start){
      return [arr];
    }
  
    var temp;
    var perms = [];
  
    for(var i = start; i &lt; length; i++){
      swapIndex(arr, i, start);
      console.log(arr);
  
      [].push.apply(perms, permutation(arr.slice(0), start + 1, last)); 
  
      swapIndex(arr, i, start);
    }
  
    return perms;
  };
  </code></pre>