title: remove the space in keys in a nested object using javascript
body: <p>I want to replace the whitespace of keys in a nested object. I have an object as follows:</p>
  
  <pre><code>     var data = 
   { 'General Information':
               { 'Referral No': '123123',
                 Marketer: '',
                 Casemanager: 'Alexis Clark',
                 'CM Username': '',
                 VOC: '',
                 'Foreign Voluntary': '',
              },
       'Account Name': 'CTS Health',
      }
  </code></pre>
  
  <p>What i did is: </p>
  
  <pre><code> for (var k in data) {
      if (k.replace(/\s/g, '') !== k) {
          data[k.replace(/\s/g, '')] = data[k];
          if (data[k] !== null &amp;&amp; typeof data[k] === 'object') {
              for (var x in data[k]) {
                  if (x.replace(/\s/g, '') !== x) {
                      data[k][x.replace(/\s/g, '')] = data[k][x];
                      delete data[k][x];
                  }
              }
          }
          delete data[k];
      }
  }
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>{ GeneralInformation:
           { 'Referral No': '123123',
             Marketer: '',
             Casemanager: 'Alexis Clark',
             'CM Username': '',
             VOC: '',
             'Foreign Voluntary': '',
          },
      AccountName: 'CTS Health',
    }
  </code></pre>
  
  <p>What i want is:</p>
  
  <pre><code>{ GeneralInformation:
           { ReferralNo: '123123',
             Marketer: '',
             Casemanager: 'Alexis Clark',
             CMUsername: '',
             VOC: '',
             ForeignVoluntary: '',
          },
      AccountName: 'CTS Health',
    }
  </code></pre>
  
  <p>What am i doing wrong here??</p>