Thank you for the help in advance. I am working in TypeScript, I’d assume any JS solution also works. I’d like to make something like this:
class ExcelData {
'Id 1': items[0].id,
'Quantity 1': items[0].quantity,
'Id 2': items[1].id,
'Quantity 2': items[1].quantity
//...
'Id 40': items[39].id,
'Quantity 40': items[39].quantity,
}
I am trying to use it with the ‘xlsx’ module to export project data into an Excel sheet. It is necessary for this module that it is a class, rather than several arrays. I could type it out manually, but there is 7 properties for every item and this would be very ugly code. It is also possible that I am later asked to add more items.
If it were Python, I could do something like this bc classes and dictionaries are different things:
excel_data = {}
for i in range (40):
excel_data['Id '+ str(i)] = items[i].id
excel_data['Quantity '+ str(i)] = items[i].quantity
What is a Typescript alternative?
Thanks!