I am trying to write a for loop to create a columns object like below:
columns: [
{data: "productCode", title: "Product Code", width: "7%"},
{data: "brand", title: "Brand", width: "10%"},
]
so far, I have tried:
Define each column attributes:
var ltColumns = {
"col1": {data: "productCode", title: "Product Code", width: "7%" },
"col2": {data: "brand", title: "Brand", width: "10%"}
};
Populate the column attributes with a for loop.
columns: [
for (var key in ltColumns) {
{
data: ltColumns[key].data,
title: ltColumns[key].title,
width: ltColumns[key].width}
}
];
However, I keep getting the error Unexpected token for. Can someone help me with the syntax?
Thanks!!