How can I get column values by column name (header) in app script. I don't want to use column indexes/column number. I want to retrieve whole column data using headers. I have tried multiple ways but couldn't get proper solution. I am using app script JavaScript for google sheet.
Here's a possible workflow.
function getColumnValues() {
const sheet = SpreadsheetApp.getActiveSheet(); // Change this according to your preferences
const header = "My header"; // Change this according to your preferences
const values = sheet.getRange(2,1,sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
const headers = values.shift();
const columnIndex = headers.indexOf(header);
const columnValues = values.map(row => row[columnIndex]);
return columnValues;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With