Convert PHP array to Javascript Ojbect

hi I’m trying to create a JavaScript object based on a template I received as a test. I use Ajax to get the data from my database but i cant seem to create the object.

 $(document).ready(function() {
          
          $.ajax({
              type: 'POST',
              url: 'fetch.php',
              datatype:'JSON',
              success: function(response) {
               
                var test=JSON.parse(response);
                var products = {};                 
                for (var x = 0; x < test.length; x++) {
                  products[x] = {productName: test[x]['name']};
                  products[x] = {category: test[x]['category']};
                  products[x] = {price: test[x]['price']};
                 
                }

                


              }
          });
     
  }); 

I’m trying to create something like this object below

products = {data: [

{
  productName: "test_item_1",
  category: "category1",
  price: "49",
  image: "test_image.jpg",
},
{
  productName: "test_item_2",
  category: "category3",
  price: "99",
  image: "test_image.jpg",
},
{
  productName: "test_item_3",
  category: "category3",
  price: "29",
  image: "test_image.jpg",
},],};