I needed to display a one-dimensional array in a 2D grid format with 3 rows and 3 columns. The array itself contains numbers from 1 to 9.
const array = Array.from({ length: 9 }, (_, i) => i + 1);
In my React component, I have it rendering as a series of div
elements:
export default function App() {
return (
<div className="App">
<div className="grid">
{array.map((cell) => (
<div className="cell">{cell}</div>
))}
</div>
</div>
);
}
Currently, the cells are displayed stacked on top of each other as expected. I'm curious if there's a way to arrange them into a 3 x 3 grid using only CSS styles, without modifying the existing DOM structure.