In my AppScript code, I've the below code, that returns perfectly columns d
and e
in a JSON format
fileID = "xxxxxxvxjRD_kjE7gzYE3WAcGdxaQEEQNReY"
sheetName = "Data"
function doGet(e) {
// Logger.log(e.parameter.method);
// Open Google Sheet using ID
var ss = SpreadsheetApp.openById(fileID);
var sheet = ss.getSheetByName(sheetName);
// Read all data rows from Google Sheet
const values = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()).getValues();
// Converts data rows in json format
const result = JSON.stringify(values.map(([a,b,c,d,e]) => ({SupplierName: d,Brand:e,})));
// Returns Result
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
The values.map(([a,b,c,d,e])
played important rule in the code above.
Now the numbers of column is increasing, and I need 2 columns, that are z
and ad
instead of d
and e
, do I need to include all the columns names in the array used in the map
function, to be:
values.map(([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t.....,ad])
Or there is abetter way to use the 2 indexes only.