Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

p5.js | p5.Table clearRows() Method

  • Last Updated : 29 May, 2020

The clearRows() method of p5.Table in p5.js is used to clear all rows in a table. It does not affect columns and their titles. It can be used to clear a table without affecting its column structure. It has no parameters.


Parameters: This function has no parameter.
The example below illustrates the clearRows() function in p5.js:


function setup() {
  createCanvas(500, 300);
  getColBtn = createButton("Get Table Row Details");
  getColBtn.position(30, 50);
  getColBtn = createButton("Clear Rows");
  getColBtn.position(30, 80);
  text("Click on the button to clear the"+
       " rows in the table", 20, 20);
  // Create the table
  table = new p5.Table();
  // Add columns
  // Add two rows
  let newRow = table.addRow();
  newRow.setString("author", "Marcel Proust");
  newRow.setString("book", "In Search of Lost Time");
  newRow = table.addRow();
  newRow.setString("author", "James Joyce");
  newRow.setString("book", "Ulysses");
function clearAllRows() {
  text("Click on the button to clear"+
       " the rows in the table", 20, 20);
  // Use the clearRow() method to
  // clear all rows in the table
  text("All rows cleared!", 20, 140);
function getTableRows() {
  text("Click on the button to clear the rows "+
       "in the table", 20, 20);
  // Display all the rows present in the table
  text("There are " + table.getRowCount() + 
       " rows in the table", 20, 140);
  for (let i = 0; i < table.getRowCount(); i++) {
    let rowContents = table.rows[i].arr.toString();
    text("Row " + i + ": " + rowContents, 20, 160 + i * 20);



Online editor:
Environment Setup:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!