Skip to content

Commit 4c2f42b

Browse files
authored
Merge pull request #2692 from seagalputra/master
Add example for p5.Table.getArray()
2 parents 1593a96 + 77916e1 commit 4c2f42b

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

src/io/p5.Table.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,18 +1120,21 @@ p5.Table.prototype.getNum = function(row, column) {
11201120
* var table;
11211121
*
11221122
* function preload() {
1123-
* //my table is comma separated value "csv"
1124-
* //and has a header specifying the columns labels
1123+
* // table is comma separated value "CSV"
1124+
* // and has specifiying header for column labels
11251125
* table = loadTable('assets/mammals.csv', 'csv', 'header');
11261126
* }
11271127
*
11281128
* function setup() {
1129-
* var tableArray = table.getArray();
1130-
*
1131-
* //output each row as array
1132-
* for (var i = 0; i < tableArray.length; i++) {
1133-
* print(tableArray[i]);
1134-
* }
1129+
* print(table.getString(0, 0)); // 0
1130+
* print(table.getString(0, 1)); // Capra hircus
1131+
* print(table.getString(0, 2)); // Goat
1132+
* print(table.getString(1, 0)); // 1
1133+
* print(table.getString(1, 1)); // Panthera pardus
1134+
* print(table.getString(1, 2)); // Leopard
1135+
* print(table.getString(2, 0)); // 2
1136+
* print(table.getString(2, 1)); // Equus zebra
1137+
* print(table.getString(2, 2)); // Zebra
11351138
* }
11361139
* </code>
11371140
* </div>
@@ -1140,6 +1143,7 @@ p5.Table.prototype.getNum = function(row, column) {
11401143
* no image displayed
11411144
*
11421145
*/
1146+
11431147
p5.Table.prototype.getString = function(row, column) {
11441148
return this.rows[row].getString(column);
11451149
};
@@ -1213,6 +1217,38 @@ p5.Table.prototype.getObject = function(headerColumn) {
12131217
*
12141218
* @method getArray
12151219
* @return {Array}
1220+
*
1221+
* @example
1222+
* <div class="norender">
1223+
* <code>
1224+
* // Given the CSV file "mammals.csv"
1225+
* // in the project's "assets" folder
1226+
* //
1227+
* // id,species,name
1228+
* // 0,Capra hircus,Goat
1229+
* // 1,Panthera pardus,Leoperd
1230+
* // 2,Equus zebra,Zebra
1231+
*
1232+
* var table;
1233+
*
1234+
* function preload() {
1235+
* // table is comma separated value "CSV"
1236+
* // and has specifiying header for column labels
1237+
* table = loadTable('assets/mammals.csv', 'csv', 'header');
1238+
* }
1239+
*
1240+
* function setup() {
1241+
* var tableArray = table.getArray();
1242+
* for (var i = 0; i < tableArray.length; i++) {
1243+
* print(tableArray[i]);
1244+
* }
1245+
* }
1246+
* </code>
1247+
* </div>
1248+
*
1249+
*@alt
1250+
* no image displayed
1251+
*
12161252
*/
12171253
p5.Table.prototype.getArray = function() {
12181254
var tableArray = [];

0 commit comments

Comments
 (0)