How do I check and update an array of JSON objects

How do I check and update an array of JSON objects

hi guys
I am trying to create a shopping basket in a JSON array and an array to be stored in the localStorage.

I want to 

1. Check if exists
2. Update the array based on ProductID
3. If it does not exist then add new values to the array
4. Then update the localstorage.

Currently my code does not update e.g. 1 + 1 is 11 instead of 2. What am i doing wrong


SEcondly the array appears to be sub arrays instead of updating it


  1.  var Basket = { ProductID: product, Quantity: quantity }; // create shopping basket values

  2.                                              //STEP 2 - create an array 
  3.                    //  
  4.           var  BasketContents = [];  // EMPTY the contents
  5.   
  6.      

  7.             // step 3 - update contents
  8.             if (localStorage.BasketContents)              //check contents
  9.             {
  10.           
  11.   
  12.          
  13.             const update = JSON.parse(localStorage.getItem('BasketContents'));
  14.     
  15.         
  16.             update.forEach(x => {if (x.ProductID == product) 
  17.             {
  18.             int count = x.Quantity + quantity;
  19.             x.Quantity = count;
  20.               BasketContents.push(update);

  21.              localStorage.removeItem('BasketContents');
  22.              localStorage.setItem('BasketContents',  JSON.stringify(BasketContents));
  23.        return;
  24.             }
  25.             else
  26.             {
  27.              BasketContents.push(Basket);
  28.  

  29.              localStorage.removeItem('BasketContents');
  30.              localStorage.setItem('BasketContents',  JSON.stringify(BasketContents));
  31.             return;
  32.             }
  33.             });