0

I saved the information of this table in an 2D array using Google Apps Script. The whole array building process worked as aspected.

Area X Y Major Minor Angle SensorNo
1 25049 380.500 246.500 190.953 167.023 0 1
2 24248 393.500 247.000 192.976 159.986 0 2
3 18250 382.500 247.000 159.023 146.121 0 3

However, as I tried to build a for loop (as seen in the following code) that goes through every column of the first row of the array I did not get the expected output. I tried to tell the loop that when the array content equals "SensorNo" to save the respective n as a new variable and then break the loop. But whenever the array content I'm looking for is in the last column the variable remains undefined...

for(n=0;n<fileContentArray[0].length;n++){
  if(fileContentArray[0][n]=="SensorNo"){
    var sensorNoCol=n;
    break;
  }
}

I hope someone can help me. Best, Max

0

1 Answer 1

1
function getHeaderColumns() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet Name");
  const hRow = 1;
  const hA = sh.getRange(hRow, 1, 1, sh.getLastColumn()).getValues()[0];
  let col = {};
  hA.forEach((h, i) => { col[h] = i + 1 });
  return col['SensorNo'];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.