Object restructure in javascript

How to do an object reconstructing in below expected format.

[{columnKey: 'ProductName',cellValue: 'samsung'}]
{
                gridRows: [{
                   gridColumns: [{
                        columnKey: 'ProductName',
                        cellValue: 'samsung',
                    },
                    {
                        columnKey: 'ProductSKU',
                        cellValue: '123',
                    },
                    {
                        columnKey: 'ProductPrice',
                        cellValue: '100',
                    }],
                },
                {
                   gridColumns: [{
                        columnKey: 'ProductName',
                        cellValue: 'nokia',
                    },
                    {
                        columnKey: 'ProductSKU',
                        cellValue: '889',
                    },
                    {
                        columnKey: 'ProductPrice',
                        cellValue: '12344',
                    }],
                },
                ],
                }
            }
gridRows: [{
                       gridColumns: [{
                            ProductName: 'samsung',
                            
                        },
                        {
                           ProductSKU: '123',
                            
                        },
                        {
                          ProductPrice: 100,
                           
                        }],
                    },
                    {
                       gridColumns: [{
                           
                            ProductName: 'nokia',
                        },
                        {
                          
                              ProductSKU: '889',
                        },
                        {
                         
                              ProductPrice: 12344,,
                        }],
                    },
                    ],
                    }
                },

I don’t have the time to write it out atm, but this would be transforming the array. Using the map method would be an easy approach for this.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.