Home > database >  How can I use the google app script to get values from one column based on a condition I set on anot
How can I use the google app script to get values from one column based on a condition I set on anot

Time:06-04

say for example i have my table that looks like this enter image description here

enter image description here

CodePudding user response:

Here is an alternative to @pgSystemTester's answer that uses a for loop.

function getFiltered() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ws = ss.getActiveSheet();
  var theValues = ws.getRange("a:b").getValues();
  
 //Removes the header row
  theValues = theValues.slice(1)
  var breakfastValues = []

  for (let i = 0; i < theValues.length; i  ) {
    if (theValues[i][0] === "Breakfast") {
       breakfastValues.push(theValues[i][1]);
    }
  }
 return breakfastValues
}
  • Related