Hey everyone, I’m having a tough time wrapping my head around this one. I have some data object with properties and each property has an array as a value. Here is an example of the data:
{
'Prop 1 (Col Header 1, Row 1)':
[
'String value (Col 1, Row 2)',
'String value (Col 1, Row 3)',
'String value (Col 1, Row 4)',
],
'Prop 2 (Col Header 2, Row 1)':
[
'String value (Col 2, Row 2)',
'String value (Col 2, Row 3)',
'String value (Col 2, Row 4)',
]
}
I have tried to make it clear what needs to happen. The properties in the object need to be the column headers and the array values need to be under each column. I had tried so many things by unshifting the column headers into their own arrays, separating values at commas to go to a new cell in combination with splitting the arrays and joining them by .join('\n')
to go to the next row. I am not quite sure how to tackle this issue. Perhaps a hash table?
The easy solution would be to have the arrays of each row, however I don’t think the data would work properly in that situation. Any help or experience with converting to CSV strings would be great.