title: how to replace modified object in array of objects using react js
body: <p>i have object structure like this,</p>
  <pre><code>[{
  &quot;id&quot;:&quot;8661c8c96df94ac78283360e0d1c86bd&quot;,
  &quot;modifiedObject&quot;:{....},
  &quot;originalObject&quot;:{...}
  },
  {
  &quot;id&quot;:&quot;1525drd616dr17d78283360e0d1c86bd&quot;,
  &quot;modifiedObject&quot;:null,
  &quot;originalObject&quot;:{...}
  },
  {
  &quot;id&quot;:&quot;6767srsr14542525276767cbd246464&quot;,
  &quot;modifiedObject&quot;:{....},
  &quot;originalObject&quot;:null
  }]
  </code></pre>
  <p>I am finding an object with the id and get the inner object(if modified object present if not original object) and then modifying the data using below code</p>
  <pre><code>    const originalCopyObject = projObjs.find(s =&gt; s.id === projectObjectId);
      const targetCopyObject = originalCopyObject.modifiedObject || originalCopyObject.originalObject; // here in this case it always be one either modified or original object
      const targetMutatedCopyObject = cloneDeep(targetCopyObject);
      if (!targetMutatedCopyObject?.glazingOrGasMaterials.length) {
        targetMutatedCopyObject.glazingOrGasMaterials = [
          ...targetMutatedCopyObject.glazingGasMaterials,
          ...targetMutatedCopyObject.glazingSimpleMaterials,
        ];          
      }
      targetMutatedCopyObject.opaqueConstructions.forEach(transformConstructions);
  </code></pre>
  <p>Now <code>targetMutatedCopyObject</code> is having one of the modifiedObject or originalObject, How can I replace this targetMutatedCopyObject object in <code>projObjs</code>.</p>
  <p>Could any one please let me know how to replace this <code>tragetMutatedCopyObject</code> in <code>projObjs</code> array of objects.</p>
  <p>Many thanks in advance.</p>
  <p>Updated Code :</p>
  <pre><code>   projObjs.map(projObj =&gt; {
      if (projObj.id === projectObjectId) {
        const targetCopyObject = projObj.modifiedObject || projObj.originalObject;
        const mutatedCopyObject = transformFormStateToMutationObject(targetCopyObject);
        if (projObj.modifiedObject) {
          return {
            ...projObj,
            modifiedObject: mutatedCopyObject
          };
        }
        if (projObj.originalObject) {
          return {
            ...projObj,
            originalObject: mutatedCopyObject
          };
        }
        return projObj;
      }
      return projObj;
    });
  }`
  </code></pre>