Is there a way to access a p5.js table object row using a string - similar to accessing a table column using its header?
For example, the following csv table contains greeting and parting in different languages:
,EN, FR
greeting, hello, bonjour
parting, goodbye, aurevoir
I want to print 'hello' without using row or column index numbers, just strings:
var table = loadTable(greet-part.csv', 'csv', 'header');
print(table.get("greeting", "EN"));
I could write some more code linking 0 to 'greeting', 1 to 'parting' etc but this would become cumbersome on a large scale:
Ideas for a more elegant solution?
CodePudding user response:
You could try findRow()
.
Not, tested, but in you case you could try something like:
table.findRow("greeting", 0).get("EN");
- the above roughly translates to find the first occurance of "gretting" on the 1st column (index 0) and retrieve that row, then from that row retrieve the value under the "EN" column
- 0 refers to column zero (since in your example it doesn't have a name))