Reference p5.Table

p5.Table

Warning

p5.Table will be removed in a future version of p5.js to make way for a new, friendlier version :)

Table objects store data with multiple rows and columns, much like in a traditional spreadsheet. Tables can be generated from scratch, dynamically, or using data from an existing file.

Examples

Syntax

p5.Table([rows])

Parameters

rows
p5.TableRow[]: An array of p5.TableRow objects

Fields

columns
An array containing the names of the columns in the table, if the "header" the table is loaded with the "header" parameter.
rows
An array containing the p5.TableRow objects that make up the rows of the table. The same result as calling getRows()

Methods

addRow

Use addRow() to add a new row of data to a p5.Table object. By default, an empty row is created. Typically, you would store a reference to the new row in a TableRow object (see newRow in the example above), and then set individual values using set().

If a p5.TableRow object is included as a parameter, then that row is duplicated and added to the table.

removeRow
Removes a row from the table object.
getRow
Returns a reference to the specified p5.TableRow. The reference can then be used to get and set values of the selected row.
getRows
Gets all rows from the table. Returns an array of p5.TableRows.
findRow
Finds the first row in the Table that contains the value provided, and returns a reference to that row. Even if multiple rows are possible matches, only the first matching row is returned. The column to search may be specified by either its ID or title.
findRows
Finds the rows in the Table that contain the value provided, and returns references to those rows. Returns an Array, so for must be used to iterate through all the rows, as shown in the example above. The column to search may be specified by either its ID or title.
matchRow
Finds the first row in the Table that matches the regular expression provided, and returns a reference to that row. Even if multiple rows are possible matches, only the first matching row is returned. The column to search may be specified by either its ID or title.
matchRows
Finds the rows in the Table that match the regular expression provided, and returns references to those rows. Returns an array, so for must be used to iterate through all the rows, as shown in the example. The column to search may be specified by either its ID or title.
getColumn
Retrieves all values in the specified column, and returns them as an array. The column may be specified by either its ID or title.
clearRows
Removes all rows from a Table. While all rows are removed, columns and column titles are maintained.
addColumn
Use addColumn() to add a new column to a Table object. Typically, you will want to specify a title, so the column may be easily referenced later by name. (If no title is specified, the new column's title will be null.)
getColumnCount
Returns the total number of columns in a Table.
getRowCount
Returns the total number of rows in a Table.
removeTokens

Removes any of the specified characters (or "tokens").

If no column is specified, then the values in all columns and rows are processed. A specific column may be referenced by either its ID or title.

trim
Trims leading and trailing whitespace, such as spaces and tabs, from String table values. If no column is specified, then the values in all columns and rows are trimmed. A specific column may be referenced by either its ID or title.
removeColumn
Use removeColumn() to remove an existing column from a Table object. The column to be removed may be identified by either its title (a String) or its index value (an int). removeColumn(0) would remove the first column, removeColumn(1) would remove the second column, and so on.
set
Stores a value in the Table's specified row and column. The row is specified by its ID, while the column may be specified by either its ID or title.
setNum
Stores a Float value in the Table's specified row and column. The row is specified by its ID, while the column may be specified by either its ID or title.
setString
Stores a String value in the Table's specified row and column. The row is specified by its ID, while the column may be specified by either its ID or title.
get
Retrieves a value from the Table's specified row and column. The row is specified by its ID, while the column may be specified by either its ID or title.
getNum
Retrieves a Float value from the Table's specified row and column. The row is specified by its ID, while the column may be specified by either its ID or title.
getString
Retrieves a String value from the Table's specified row and column. The row is specified by its ID, while the column may be specified by either its ID or title.
getObject
Retrieves all table data and returns as an object. If a column name is passed in, each row object will be stored with that attribute as its title.
getArray
Retrieves all table data and returns it as a multidimensional array.
Notice any errors or typos? Please let us know. Please feel free to edit src/io/p5.Table.js and open a pull request!

Related References