Skip to content

Commit

Permalink
Merge pull request #2692 from seagalputra/master
Browse files Browse the repository at this point in the history
Add example for p5.Table.getArray()
  • Loading branch information
lmccart authored Mar 12, 2018
2 parents 1593a96 + 77916e1 commit 4c2f42b
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions src/io/p5.Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,18 +1120,21 @@ p5.Table.prototype.getNum = function(row, column) {
* var table;
*
* function preload() {
* //my table is comma separated value "csv"
* //and has a header specifying the columns labels
* // table is comma separated value "CSV"
* // and has specifiying header for column labels
* table = loadTable('assets/mammals.csv', 'csv', 'header');
* }
*
* function setup() {
* var tableArray = table.getArray();
*
* //output each row as array
* for (var i = 0; i < tableArray.length; i++) {
* print(tableArray[i]);
* }
* print(table.getString(0, 0)); // 0
* print(table.getString(0, 1)); // Capra hircus
* print(table.getString(0, 2)); // Goat
* print(table.getString(1, 0)); // 1
* print(table.getString(1, 1)); // Panthera pardus
* print(table.getString(1, 2)); // Leopard
* print(table.getString(2, 0)); // 2
* print(table.getString(2, 1)); // Equus zebra
* print(table.getString(2, 2)); // Zebra
* }
* </code>
* </div>
Expand All @@ -1140,6 +1143,7 @@ p5.Table.prototype.getNum = function(row, column) {
* no image displayed
*
*/

p5.Table.prototype.getString = function(row, column) {
return this.rows[row].getString(column);
};
Expand Down Expand Up @@ -1213,6 +1217,38 @@ p5.Table.prototype.getObject = function(headerColumn) {
*
* @method getArray
* @return {Array}
*
* @example
* <div class="norender">
* <code>
* // Given the CSV file "mammals.csv"
* // in the project's "assets" folder
* //
* // id,species,name
* // 0,Capra hircus,Goat
* // 1,Panthera pardus,Leoperd
* // 2,Equus zebra,Zebra
*
* var table;
*
* function preload() {
* // table is comma separated value "CSV"
* // and has specifiying header for column labels
* table = loadTable('assets/mammals.csv', 'csv', 'header');
* }
*
* function setup() {
* var tableArray = table.getArray();
* for (var i = 0; i < tableArray.length; i++) {
* print(tableArray[i]);
* }
* }
* </code>
* </div>
*
*@alt
* no image displayed
*
*/
p5.Table.prototype.getArray = function() {
var tableArray = [];
Expand Down

0 comments on commit 4c2f42b

Please sign in to comment.