p5.js | loadTable() Function
The loadTable() function is used to read the contents of a file or URL and create a p5.Table object from it. The options parameter can be used to define the type of format that the data is expected to be read. All the files loaded and saved are in UTF-8 encoding.
This function is asynchronous, therefore it is recommended to be called in the preload() function to ensure that the function is executed before the other functions.
loadTable(filename, options, [callback], [errorCallback])
loadTable(filename, [callback], [errorCallback])
Parameters: This function accepts four parameter as mentioned above and described below.
- filename: This is a string which denotes the file path or URL from where the data has to be loaded.
- options: It is a string which denotes the format of the file to be loaded. It can be either “csv” which loads the table using comma-separated-values or “tsv” which loads the table using tab-separated-values. Also the value “header” can be specified to denote if the table has a header value. Multiple commands can be used by passing them as separate parameters. It is an optional parameter.
- callback: This is a function which is called when this function executes successfully. The first argument for this function is the XML data loaded from the file. It is an optional parameter.
- errorCallback: This is a function which is called if there is any error in executing the function. The first argument for this function is the error response. It is an optional parameter.
Below examples illustrate the loadTable() function in p5.js:
Online editor: https://editor.p5js.org/