I need to limit the map functionality to only include columns within the specified range that are also present in the headers
list, which is a subset of the values in v[0]
. This ensures that only values from columns listed in the headers
array will be modified.
function test() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sht = ss.getSheetByName('Elements');
var rng = sht.getDataRange();
var v = rng.getValues();
var headers = ['Id', 'Label'];
//headers is a subset of v[0]
//This will work for `all` values of the values
//values = v.map(x => x.map(y => y==("Networking - 1") ? 1: y));
values = v.map(x => x.map(y => cols.includes(y) == true && y=="Networking - 1" ? 1 : y))
var sht2 = ss.getSheetByName('AAA');
sht2.getRange(1,1, v.length, v[0].length).setValues(v);
}