0

The Range class seems to view the table as an array of rows. It has the method getDataTable which returns an opaque DataTable. Lost in this seems to be how to select a column as an array. Even an Nx1 range, i.e. just a column, comes in the form [ [1], [2], [3], ...] instead of flat.

Is selecting a column really so suboptimal that it's that hard to do? I'm mostly hardcoding data so I can just rotate it if it is an optimization, just seems odd.

djechlin
  • 59,258
  • 35
  • 162
  • 290
  • I agree it has caused me some grief. I often find it necessary to have a switch statement in my code because you have to do one way if you get a single row, another way if get a single column and yet another way if you have multiple columns and rows. But I'm guessing a lot of code would break if you change it now. – Cooper Feb 21 '17 at 04:16
  • ss.getRange("A1:A").getValues().flat() I don't know what dot flat is or where it is documented but it makes a [[x], [x], [x],...} into {x, x, x, ...] – aNewb Aug 16 '21 at 18:51

1 Answers1

1

There is no specific method to select a column. You are always selecting a 2D table even if it has only one column.
The first dimension is for the row the second for the values in this row (aka the column values in this row). It's quite convenient to use. You can access whatever you want with the combination [row number][column number]. You'll also find a little everywhere methods to deal with it like transpose or get a column values of simply filter...
You just need to practice a little.

Community
  • 1
  • 1
Harold
  • 3,297
  • 1
  • 18
  • 26