title: remove null values from arrays with splice
body: <p>I'm trying to make a function to remove null values from multidimensional arrays, but it doesn't work very well. It does not penetrate to the last layer of arrays, and does not remove when two null values are adjacent. </p>
  
  <pre><code>function isArray(obj) {
      // http://stackoverflow.com/a/1058753/1252748
      return Object.prototype.toString.call(obj) === '[object Array]';
  }
  
  function removeEmptyArrayElements(obj) {
  
      for (key in obj) {
          if (obj[key] === null) {
  
              obj = obj.splice(key, 1);
  
          }
          var isArr = isArray(obj[key]);
          if (isArr) {
              removeEmptyArrayElements(obj[key]);
          }
  
      }
      return obj;
  }
  </code></pre>