title: How to update deeply nested array of objects?
body: <p>I have the following nested array of objects:</p>
  <pre><code>const data = [
    {
      product: {
        id: &quot;U2NlbmFyaW9Qcm9swkdWN0OjEsz&quot;,
        currentValue: 34300,
      },
      task: {
        id: &quot;R2VuZXJpY1Byb2R1Y3Q6MTA&quot;,
        name: &quot;My Annuity&quot;,
      },
      instrumentDetails: [
        {
          instrument: {
            id: &quot;U2NlbmFyaW9JbnN0cnVtZW50OjEz&quot;,
            supplier: {
              id: &quot;U3VwcGxpZXJJbnN0cnVtZW50OjUzNjQ&quot;,
              supplierDetails: {
                name: &quot;Local - Class A&quot;,
              },
            },
            currentValue: 44323,
          },
          assets: {
            current: 1.2999270432626702,
            fixed: 0.5144729302004819,
            financial: 0.0723506386331588,
            cash: 0.00006003594786398524,
            alternative: 0.05214078143244779,
            property: 0.548494862567579,
            local: 0.10089348539739094,
            global: 0,
          },
        },
      ],
    },
    {
      product: {
        id: &quot;U2NlbmFyaW9Qcm9swkfefewdWN0OjEsz&quot;,
        currentValue: 3435300,
      },
      task: {
        id: &quot;R2VuZXJpYfewfew1Byb2R1Y3Q6MTA&quot;,
        name: &quot;Living&quot;,
      },
      instrumentDetails: [
        {
          instrument: {
            id: &quot;U2NlbmFyadewwW9JbnN0cnVtZW50OjEz&quot;,
            supplier: {
              id: &quot;U3VwcGxpZdwdwXJJbnN0cnVtZW50OjUzNjQ&quot;,
              supplierDetails: {
                name: &quot;Local - Class B&quot;,
              },
            },
            currentValue: 434323,
          },
          assets: {
            current: 1.294353242,
            fixed: 0.514434242004819,
            financial: 0.07434286331588,
            cash: 0.0000434398524,
            alternative: 0.05242348143244779,
            property: 0.543242567579,
            local: 0.100432439739094,
            global: 0,
          },
        },
      ],
    },
  ];
  </code></pre>
  <p>The above data presents an array of products which consist of instruments that are described in instrumentDetails array. I am trying to find an instrument by supplier id and update its assets by multiplying all of the asset values by a given number.</p>
  <p>Here is my function:</p>
  <pre><code>export const updateObject = (
    productsArr: any,
    supplierInstrumentId: string
  ) =&gt; {
    return productsArr.map(
      (product: any) =&gt; {
        product.instrumentDetails.map(
          (instrumentDetail: any) =&gt; {
            if (
              instrumentDetail.instrument.supplier.id ===
              supplierInstrumentId
            ) {
              instrumentDetail.assets.current = instrumentDetail.assets.current + 5;
              instrumentDetail.assets.fixed= instrumentDetail.assets.fixed+ 5;
              instrumentDetail.assets.financial= instrumentDetail.assets.financial+ 5;
              instrumentDetail.assets.cash= instrumentDetail.assets.cash+ 5;
            }
          }
        );
      }
    );
  };
  </code></pre>
  <p>This function is giving an error :</p>
  <blockquote>
  <p>Uncaught TypeError: Cannot assign to read only property 'current' of
  object '#'</p>
  </blockquote>
  <p>How can I deeply update the above data? Please help.</p>