I want to display array of objects in 2 columns in a table. what is the easiest method to display the list as two columns?
const columns = [
{
subHeading: "A",
subText: ["1", "2"]
},
{
subHeading: "B",
subText: ["3", "4"]
},
{
subHeading: "C",
subText: ["5", "6"]
},
{
subHeading: "D",
subText: ["7", "8"]
}
];
Desired display on HTML Page:
A B
C D
2
Answers
You can use
Grid
here as:CODESANDBOX
Displaying content in 2 columns can be easily done with CSS-Grid by using
display: grid; grid-template-columns: repeat(2, 1fr);
. This is not an appropriate task for a table as it is not tabular data!Creating the content dynamically can be done by looping through the arrays and using
createElement
:I just added the elements to the body directly. You can add them into a container of you choice.