Ok so I have a spreadsheet which we extract a 2d array of values from. But really I want one variable per line of this 2d array. The following code does work... but is this the best way to do it?
function testAssignments(){
config = ss.getRange("C2:C6").getValues();//2D Array
result = []
config.forEach(x => result.push(x[0]))
var [a,b,c,d,e] = result;
console.log(a,b,c,d,e);
}
I also tried the line config.forEach(x=> x=x[0]) but that didn't work for some reason.
is this the best way to do it?. So I answer as a comment. As another direction, how about the following sample scripts? 1.const v = config.reduce((o,[c],i) => (o[String.fromCharCode(97 + i)] = c, o), {})In this script, the values can be retrieved byv.a, v.b,,,. 2.config.forEach(([c],i) => this[String.fromCharCode(97 + i)] = c)In this case, the values can be retrieved bya, b,,,. But in this case, these variables are declared as the global.