diva-D
3/11/2020 - 8:07 AM

Create row data based on headers

Assuming you have an object with keys that match the column headers, this script will create an row array in the precise column order.

const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
let requestArray = [];
headers.forEach(function(key){
  if(requestObj.hasOwnProperty(key)){
    requestArray.push(requestObj[key]);
  } else {
    requestArray.push("");
  }
})