title: How do I remove all null and empty string values from an object?
body: <p>Can you please tell me how to remove all null and empty string values from an object? I am getting an error while deleting the key.</p>
  <p>This is what I have so far, but it doesn't work properly:</p>
  <pre><code>$.each(sjonObj, function(key, value) {
      if(value == &quot;&quot; || value == null) {
          delete sjonObj.key;
      }
  });
  </code></pre>
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var sjonObj= {
    "executionMode": "SEQUENTIAL",
    "coreTEEVersion": "3.3.1.4_RC8",
    "testSuiteId": "yyy",
    "testSuiteFormatVersion": "1.0.0.0",
    "testStatus": "IDLE",
    "reportPath": "",
    "startTime": 0,
    "durationBetweenTestCases": 20,
    "endTime": 0,
    "lastExecutedTestCaseId": 0,
    "repeatCount": 0,
    "retryCount": 0,
    "fixedTimeSyncSupported": false,
    "totalRepeatCount": 0,
    "totalRetryCount": 0,
    "summaryReportRequired": "true",
    "postConditionExecution": "ON_SUCCESS",
    "testCaseList": [
      {
        "executionMode": "SEQUENTIAL",
        "commandList": [
          
        ],
        "testCaseList": [
          
        ],
        "testStatus": "IDLE",
        "boundTimeDurationForExecution": 0,
        "startTime": 0,
        "endTime": 0,
        "label": null,
        "repeatCount": 0,
        "retryCount": 0,
        "totalRepeatCount": 0,
        "totalRetryCount": 0,
        "testCaseId": "a",
        "summaryReportRequired": "false",
        "postConditionExecution": "ON_SUCCESS"
      },
      {
        "executionMode": "SEQUENTIAL",
        "commandList": [
          
        ],
        "testCaseList": [
          {
            "executionMode": "SEQUENTIAL",
            "commandList": [
              {
                "commandParameters": {
                  "serverAddress": "www.ggp.com",
                  "echoRequestCount": "",
                  "sendPacketSize": "",
                  "interval": "",
                  "ttl": "",
                  "addFullDataInReport": "True",
                  "maxRTT": "",
                  "failOnTargetHostUnreachable": "True",
                  "failOnTargetHostUnreachableCount": "",
                  "initialDelay": "",
                  "commandTimeout": "",
                  "testDuration": ""
                },
                "commandName": "Ping",
                "testStatus": "IDLE",
                "label": "",
                "reportFileName": "tc_2-tc_1-cmd_1_Ping",
                "endTime": 0,
                "startTime": 0,
                "repeatCount": 0,
                "retryCount": 0,
                "totalRepeatCount": 0,
                "totalRetryCount": 0,
                "postConditionExecution": "ON_SUCCESS",
                "detailReportRequired": "true",
                "summaryReportRequired": "true"
              }
            ],
            "testCaseList": [
              
            ],
            "testStatus": "IDLE",
            "boundTimeDurationForExecution": 0,
            "startTime": 0,
            "endTime": 0,
            "label": null,
            "repeatCount": 0,
            "retryCount": 0,
            "totalRepeatCount": 0,
            "totalRetryCount": 0,
            "testCaseId": "dd",
            "summaryReportRequired": "false",
            "postConditionExecution": "ON_SUCCESS"
          }
        ],
        "testStatus": "IDLE",
        "boundTimeDurationForExecution": 0,
        "startTime": 0,
        "endTime": 0,
        "label": null,
        "repeatCount": 0,
        "retryCount": 0,
        "totalRepeatCount": 0,
        "totalRetryCount": 0,
        "testCaseId": "b",
        "summaryReportRequired": "false",
        "postConditionExecution": "ON_SUCCESS"
      }
    ]
  };
  
  $.each(sjonObj, function(key, value) {
      if(value == "" || value == null) {
          delete sjonObj.key;
      }
  });
  
  console.log(sjonObj);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>