title: How to replacing properties of an json object with new
body: <p>This object generates depends on custom fields that come from the backend.
  Need a function that replaces some fields on a new and other delete or not include in submit object</p>
  <pre><code> {
      &quot;originating_office&quot;: {
        &quot;code&quot;: &quot;string&quot;, **replace on &quot;value&quot;: &quot;string&quot;,**
        &quot;description&quot;: &quot;string&quot; **replace on &quot;label&quot;: &quot;string&quot;**
      },
      &quot;petty_cash_account&quot;: {
        &quot;number&quot;: &quot;string&quot;, **replace on &quot;value&quot;: &quot;string&quot;,**
        &quot;name&quot;: &quot;SOME DATA&quot;, **replace on &quot;value&quot;: &quot;string&quot;,**
        &quot;gls_account&quot;: &quot;SOME DATA-HERE&quot;, **just add new filed**
        &quot;currency&quot;: &quot;SOME&quot;, **just add new filed**
        &quot;origination_office_of&quot;: &quot;&quot; **just add new filed**
      },
      &quot;item&quot;: &quot;simple string&quot;,
      &quot;amount&quot;: &quot;0.7&quot;,
      &quot;spending_unit&quot;: {
        &quot;indexno&quot;: &quot;08805544&quot;, **save**
        &quot;display_name&quot;: &quot;Mark Twen&quot;, **delete**
        &quot;position_title&quot;: null, **delete**
        &quot;org_unit_name&quot;: &quot;&quot;, **delete**
        &quot;extension&quot;: null, **delete**
        &quot;country&quot;: &quot;Italy&quot;, **delete**
        &quot;duty_station&quot;: &quot;2250&quot;, **delete**
        &quot;email&quot;: &quot;user@example.com&quot;, **save**
        &quot;last_name&quot;: &quot;Some&quot;, **save**
        &quot;first_name&quot;: &quot;Data&quot;, **save**
        &quot;username&quot;: &quot;some.data&quot;, **delete**
        &quot;text&quot;: &quot;Some DATA&quot; **save**
      },
    }
  </code></pre>
  <p>But can't imagine what to do forward</p>
  <pre><code>const replaceDataByNew = (obj) =&gt; {
    for (let i = 0; i &lt; obj.length; i++) {
      if (obj[i].hasOwnProperty('originating_office')) {
        console.log(&quot;originating_office&quot;);
        
      }
      if (obj[i].hasOwnProperty('cash_collected')) {
        console.log(&quot;cash_collected&quot;);
      }
    }
  };
  
  replaceDataByNew(data);
  </code></pre>
  <p>I tried to refactor this next approach: <a href="https://stackoverflow.com/questions/6418814/replacing-a-property-value-in-json">Replacing a property value in JSON</a>, but unfortunately. I will appreciate it if you help me</p>