getColumn

Category:Data

Retrieves the values stored in a given column of a data table and returns them in a list.

You can only retrieve values from data tables you have already imported into your AppLab project or level.

Examples

US States

//Assume the dataset "US States" has already been imported

var stateNames = getColumn("US States", "State Name");
console.log("There are " + stateNames.length + " states in the US.");
console.log(stateNames);

Cereal Nutrition

Each "Run" of this code will generate a sentence with a random cereal's name and nutritional information.

//Assume the dataset "Cereal Nutrition" has already been imported

var cerealNames = getColumn("Cereal Nutrition", "Name") ;
var cerealProtein = getColumn("Cereal Nutrition", "Grams of  Protein") ;
var cerealFiber = getColumn("Cereal Nutrition", "Grams of Fiber") ;
var randomIndex = randomNumber(0, cerealNames.length-1);
console.log(cerealNames[randomIndex] + " has " + cerealProtein[randomIndex] + " grams of protein and " + cerealFiber[randomIndex] + " grams of fiber." );

Syntax

getColumn(table, column)

Parameters

NameTypeRequired?Description
table String The name of the table containing the column of values to be retrieved.
column String The name of the column containing the values to be retrieved.

Returns

A list containing the values from the column in the data table.

Tips

If you make multiple lists from different columns contained in the same table, they will all have the same length and values from the a given row will all have the same index in their respective lists.

Found a bug in the documentation? Let us know at documentation@code.org