title: how to update the nested object array in javascript
body: <p>I would like to know how to update object array in javascript.</p>
  
  <p>how to update original_sample with sample objects sent as argument to the function and perform calculation as shown</p>
  
  <p>here, how to do different calcuation <code>with payfee</code> and <code>without payfee</code> in a single function and update the object</p>
  
  <p>Gotstuck and how to do in javascript.</p>
  
  <pre><code>// update the original_sample with sample2 values
  var res = getValue(original_sample, sample2);
  // update the original_sample with sample3 values
  var res = getValue(original_sample, sample3);
  function getValue(original, sample){
  return original.map(({ fee, rate, ...others }) =&gt; ({
      id: 'trans'
      amount: amount,
      fee: +fee,
      rate: +rate,
      targetamount: (amount-fee)*rate
    }))
  }
  </code></pre>
  
  <pre><code>//inputs
  var original_sample= [{
       id: "trans",
       fee: 1,
       rate: 2.2,
       amount:100,
    }]
  //passed as input to update original_sample
  var sample2 = [{
     id: "trans",
     fee: 2,
     rate: 4.0,
     payfee: 1%,
     amount: 100,
    }]
  //passed as input to update original_sample
  var sample3 =[{
   id: "trans",
   fee: 1,
   rate: 1.0,
   amount: 100
     }]
  </code></pre>
  
  <pre><code>Expected Result:
  //getValue(original_sample, sample2);
  res= [{
     id: "trans"
     fee: 2,
     rate: 4.0,
     payfee: 1,
     amount: 100,
  targetamount: 388.08
      }]
  
  //getValue(original_sample, sample3);
  res=[{
   id: "trans",
   fee: 1,
   rate: 1.0,
   amount: 100,
  targetamount: 99
     }]
  
  </code></pre>