I am writing a script to use on a google sheet where I am accepting user input and comparing it to the values already present on the spreadsheet.
In the function below I have retrieved the users desired number with the variable voltReqed.
I am attempting to compare it (detect less than or greater than) to each value in the array generated with the variable voltCompareData.
I am quite new to scripts, please excuse my ignorance.
function getVoltage() {
var voltReqed = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("A1").getValue();
Logger.log(voltReqed);
var voltCompareData = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SpecsList").getSheetValues(3, 2, 1, 3);
Logger.log(voltCompareData);
var voltSample1 = voltCompareData.getValue(1,1);
Logger.log(voltSample1);
}
The variable voltSample1 was me attempting to pull the first number out of the array generated by the voltCompareData variable for comparison operations. Please see the image for the number and array retrieved and logged by the above script.
CodePudding user response:
Comparing data to variable
function getVoltage() {
var voltReqed = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("A1").getValue();
var vs = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SpecsList").getSheetValues(3, 2, 1, 3).flat();
vs.forEach(e => {
if(e == v) {
//do someting
}
});
}