p5.Table getRowCount() Method

The getRowCount() method of p5.Table in p5.js is used to return the total number of rows in a table object.
Syntax:
getRowCount()
Parameters: This function does not accept any parameters.
Return Value: It returns an integer value which specifies the number of rows in the table.
Below example illustrates the getRowCount() method in p5.js:
Example:
| let rowCount = 1;  functionsetup() {   createCanvas(500, 400);   textSize(16);    addRowBtn = createButton("Add Row");   addRowBtn.position(30, 50);   addRowBtn.mouseClicked(addOneRow);    removeRowBtn =     createButton("Clear Last Row");   removeRowBtn.position(160, 50);   removeRowBtn.mouseClicked(clearLastRow);    // Create the table   table = newp5.Table();    // Add columns   table.addColumn("book");   table.addColumn("price");    // Display the table   showTable(); }  functionaddOneRow() {   let newRow = table.addRow();   newRow.set('book', "Book "+ rowCount);   newRow.set('price', "Price "+     (rowCount * random(1, 10)).toFixed(1));    rowCount++;    showTable(); }  functionclearLastRow() {   let lastRow = table.getRowCount() - 1;   if(lastRow >= 0)      table.removeRow(lastRow);    showTable(); }  functionshowTable() {   clear();   text("Click on the buttons to change"+        " the number of rows in the table",        20, 20);    // Get the number of rows in the table   let rowCount = table.getRowCount();    // Display the total rows   // present in the table   text("There are "+ rowCount +        " rows in the table", 20, 100);    // Show all the rows currently   // present in the table   for(let r = 0; r < rowCount; r++) {     let currRow = table.rows[r].arr.toString();     currRow = currRow.split(", ").join("  ");      text(currRow, 30, 140 + r * 20);   } }  | 
Output:
Online editor: https://editor.p5js.org/
Environment Setup: https://www.zambiatek.com/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5.Table/getRowCount
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					



