title: How to push items in JSON Object array in react?
body: <p>I have my REACT JS client side and using PHP APIs to fetch data. Im fetching the JSON Object array from API call, in the following format:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
      "records": {
          "Master Automotives": [
              {
                  "SparePartID": "43",
                  "Name": "Oil and Lubricants",
                  "Price": "4500",
                  "VendorID": "48",
                  "CompanyName": "Master Automotives"
              },
              {
                  "SparePartID": "45",
                  "Name": "Lights",
                  "Price": "2300",
                  "VendorID": "48",
                  "CompanyName": "Master Automotives"
              }
          ],
          "Repair Solutions": [
              {
                  "SparePartID": "47",
                  "Name": "Steering Wheel",
                  "Price": "1500",
                  "VendorID": "60",
                  "CompanyName": "Repair Solutions"
              }
          ],
          
           "FiveStar Automotives": [
              {
                  "SparePartID": "51",
                  "Name": "Brakes",
                  "Price": "234",
                  "VendorID": "70",
                  "CompanyName": "FiveStar Automotives"
              },
              {
                  "SparePartID": "53",
                  "Name": "Clutch",
                  "Price": "999",
                  "VendorID": "70",
                  "CompanyName": "FiveStar Automotives"
              },
                {
                  "SparePartID": "55",
                  "Name": "LED",
                  "Price": "288",
                  "VendorID": "70",
                  "CompanyName": "FiveStar Automotives"
              }
          ]
      }
  }</code></pre>
  </div>
  </div>
  
   From API response, I want to save the above response data (NAME and PRICE) in this.state of <strong>myrecords[]</strong> (which is empty initially)  Plus I also want to push some more items to this above JSON, like for each <strong>SPAREPART</strong> I want to add "<strong>Quantity</strong>" and "<strong>TotalPrice</strong>" items for each data.</p>
  
  <p>Im trying to use <strong>.push</strong> method to add these Quantity &amp; TotalPrice for each data item. here is my REACT API call where I m fetching data and saving it by <strong>setState</strong> of <strong>myrecords[]</strong> and pushing more items in it but IT DOESN'T WORK and shows ERROR msg. please <strong>HELP</strong> ME how to PUSH the items correctly.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>axios.post('http://localhost/Auth/api/customers/show_cart.php', arr,
       {
      headers: {'Accept': 'application/json, text/plain, */*',
                'Content-Type': 'application/json'}
      } )
      .then(response =&gt; {
        console.log(response.data.records);
  
        let myItems = [];
      response.data.records.forEach((item) =&gt; {
        myItems.push({SparePartID: item.SparePartID,
           Name: item.Name,
           Price: item.Price,
  
           Quantity: 1,
           totalPrice: item.Price});
          })
  
        this.setState({
                myrecords: myItems
             })
          })
       .catch(error =&gt; {
       if (error) {
         console.log("REACT Error. Cannot show cart items");  }
         });</code></pre>
  </div>
  </div>
  </p>