Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js | p5.Table getColumn() Method

Improve Article
Save Article
  • Last Updated : 01 Jun, 2020
Improve Article
Save Article

The getColumn() method of p5.Table in p5.js is used to retrieve all values in the given column and return them in the form of an array. The column to be returned may be given in the form of its title or ID.

getColumn( column )

Parameters: This function accepts a single parameter as mentioned above and described below: 

  • column: It is a String or Number which denotes the title or the number of the column to return.

Return Value: It returns an array of column values as specified by the column parameter.
The example below illustrates the getColumn() function in p5.js:


function setup() {
  createCanvas(500, 200);
  getColBtn = createButton("Get Column Values");
  getColBtn.position(30, 50);
  text("Click on the button to get column values", 20, 20);
  // Create the table
  table = new p5.Table();
  // Add two columns
  // using addColumn
  // Add two rows
  let newRow = table.addRow();
  newRow.setString("author", "Dennis Ritchie");
  newRow.setString("language", "C");
  newRow = table.addRow();
  newRow.setString("author", "Bjarne Stroustrup");
  newRow.setString("language", "C++");
function getCols() {
  // Array of values in the column "author"
  author_col = table.getColumn("author");
  text("Column author: ", 20, 100);
  // Loop through the array to display the values
  for (let i = 0; i < author_col.length; i++) {
    text(author_col[i], 170 + i * 120, 100);
  // Array of values in the column "language"
  language_col = table.getColumn("language");
  text("Column language: ", 20, 120);
  // Loop through the array to display the values
  for (let i = 0; i < language_col.length; i++) {
    text(language_col[i], 170 + i * 120, 120);



Online editor:
Environment Setup:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!