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.
//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);
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." );
getColumn(table, column)
Name | Type | Required? | 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. |
A list containing the values from the column in the data table.
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