Skip to content
Related Articles

Related Articles

p5.Table getArray() Method

Improve Article
Save Article
  • Last Updated : 16 Jul, 2020
Improve Article
Save Article

The getArray() method of p5.Table in p5.js is used to retrieve all the data in the table as a multidimensional array. This array can be iterated through to get all the values in the table.



Parameters: This method does not accept any parameters.

Return Value: This method returns a multidimensional array that contains all the data of the table.

The example below illustrates the getArray() method in p5.js:



function setup() {
  createCanvas(600, 300);
  text("Click on the button to get the " +
       "values of the table as an array",
       20, 20);
  setBtn =
    createButton("Get all table values");
  setBtn.position(30, 40);
  // Create the table
  table = new p5.Table();
function setTableData() {
  let tableRow = table.addRow();
  tableRow.setString('Invention', 'Telescope');
  tableRow.setString('Inventors', 'Galileo');
  tableRow = table.addRow();
  tableRow.setString('Invention', 'Steam Engine');
  tableRow.setString('Inventors', 'James Watt');
  tableRow = table.addRow();
  tableRow.setString('Invention', 'Radio');
  tableRow.setString('Inventors', 'Guglielmo Marconi');
function showTable() {
  text("All values of the table are retrieved " +
       "using the getArray() method", 20, 20);
  // Get all the values in the table as an array
  let tableArray = table.getArray();
  // Show all the rows currently
  // present in the multi-dimensional array
  for (let r = 0; r < tableArray.length; r++) {
    for (let c = 0; c < tableArray[0].length; c++) {
           20 + 160 * c, 100 + 20 * r);


Console Output:

Online editor:

Environment Setup:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!