title: JS - Separate nested arrays into a contained array
body: <p>I want to take all sub-arrays in a nested array, making a new array out of each depth (including the original input array), and place them into a new array. </p>
  
  <p>Input:</p>
  
  <pre><code>var array = ["cat", ["dog", ["rabbit"]], "hamster"]
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>newArray = [
               ["cat", ["dog", ["rabbit"]], "hamster"], 
               ["dog", ["rabbit"]], 
               ["rabbit"]
             ]
  </code></pre>
  
  <p>Attempt: </p>
  
  <pre><code>var unnest = function(array) {
    var container = [array];
      for (var i in array) {
          if (array[i] instanceof Array) {
            container.push(array[i]);
          }
      }
    return container
  }
  </code></pre>
  
  <p>I know this needs some sort of iterative or recursive process, but that's where I'm stuck (I'm new to JavaScript). Thanks.</p>