title: Recursively remove object which contains empty array in nest json object
body: <p>I want to dynamically delete json object which contains empty array. I've found this link <a href="https://stackoverflow.com/q/9446426/3606247">similar question here</a>. But it doesn't work for me in my case.</p>
  
  <p>Suppose I have a JSON object:</p>
  
  <pre><code>{"op":"1","parameters":[{"op":"2-1","parameters":[]},{"op":"2-2","parameters":[1,2]}]}
  </code></pre>
  
  <p>I've wrote a sample code to do the stuff recursively:</p>
  
  <pre><code>function removeEmptyArray(cJSON){
      if(!cJSON)
          return cJSON;
  
      for(var i=cJSON.parameters.length-1;i&gt;=0;i--){
          if(!(cJSON.parameters[i].parameters instanceof Array))
              continue;
          if(cJSON.parameters[i].parameters.length==0){
              cJSON.parameters.splice(i,1);
          }else{
              cJSON.parameters[i] = removeEmptyArray(cJSON.parameters[i]);
          }
      }
      return cJSON;
  
  }
  </code></pre>
  
  <p>the expect result is <code>{"op":"1","parameters":[{"op":"2-2","parameters":[1,2]}]}</code>, the code works fine.</p>
  
  <p>but when I have this obj:</p>
  
  <pre><code>{"op":"1","parameters":[{"op":"2-1","parameters":[{"op":"3-1","parameters":[]}]},{"op":"2-2","parameters":[1,2,3]}]}
  </code></pre>
  
  <p>The output is <code>{"op":"1","parameters":[{"op":"2-1","parameters":[]},{"op":"2-2","parameters":[1,2,3]}]}</code></p>
  
  <p>Obviously it does not dynamically remove the json obj whose "op" is "2-1".</p>
  
  <p>So how to solve it in an elegant way, using pure javascript? </p>