I want to switch rows to columns , please provide javascript or react js format . Thank you
const dataArray = [
{ product: "Product 1", year: "2009", sales: "1212" },
{ product: "Product 2", year: "2009", sales: "522" },
{ product: "Product 3", year: "2010", sales: "1337" },
];
//App.js
function App() {
const renderOriginalTable = (data, index) => {
return (
<tr key={index}>
<td>{data.product}</td>
<td>{data.year}</td>
<td>{data.sales}</td>
</tr>
)
};
return (
<div className="container">
<h2>Original Table</h2>
<table className="originalTable">
<thead>
<tr>
<th>Product</th>
<th>Year</th>
<th>Sales</th>
</tr>
</thead>
<tbody>{dataArray.map(renderOriginalTable)}</tbody>
</table>
</div>
);
}
export default App
According to the code above, table will be as below :
Product | Year | Sales
Product 1 | 2009 | 1212
Product 2 | 2009 | 522
Product 3 | 2010 | 1337
But I want the same data to be dispalyed as
Product | Product 1 | Product 2 | Product 3
Year | 2009 | 2009 | 2010
Sales | 1212 | 522 | 1337
by converting rows into columns from the above mentioned jsan data.
Thank You