Skip to content
Advertisement

Access, transpose, and join data from a .csv file

I have a CSV File which is laid out as so:

JavaScript

My code:

JavaScript

This produces three strings, which are needed to plot a graph.

JavaScript

However it is likely that I will be adding more columns to the csv file, so I need a way of looping around to avoid having to manually add new lines each time. I cannot seem to find a way to perform a loop which would give the variable names automatically for the columns without it breaking.

Advertisement

Answer

Use an array of strings for columns instead of $column1,2,3..:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement