Modifying JSON data
<p>I have a following sample data, which i modify based on certain logic and return back modified object</p>

<pre><code>var obj = [{
  Primary: "Hejrwe",
  TestVal: "234723",
  TestTool: [{
    label: 'xyz',
    num: '23'
  }, {
    label: "",
    num: ""
  }, {
    label: "",
    num: ""
  }],
  TestItv: [{
    label: 'xyz',
    num: '23'
  }, {
    label: "",
    num: ""
  }, {
    label: "",
    num: ""
  }]
}, {
  Primary: "Urwhe",
  TestVal: "32432",
  TestTool: [{
    label: 'abc',
    num: '24'
  }, {
    label: "",
    num: ""
  }, {
    label: "",
    num: ""
  }],
  TestItv: [{
    label: 'abc',
    num: '24'
  }, {
    label: "",
    num: ""
  }, {
    label: "",
    num: ""
  }]
}];
</code></pre>

<p>I am trying to remove any keys where the "label" and "num" key values are empty strings in the TestTool array, and currently i am solving with the following</p>

<pre><code>var newObj = {};
Object.keys(obj).map(function(index) {
  var val = obj[index].TestTool;
  var temp = [];

  for (var i in val) {
    if (val[i].label !== "" || val[i].num !== "") {
      temp.push(val[i]);
      //delete val[i];
    }
  }

  obj[index].TestTool = temp;
  newObj = obj;
 });

 console.log(newObj); 
</code></pre>

<p>In the above code "newObj" returns back the modified object, but if you look at the logic applied i am using a temporary array to store the values and then reassign the to the "TestTool" key.</p>

<p>Is there a better solution for this, where i could delete the values as i go through the object?   </p>