I want to get a data set and splice
off some irrelevant lines, preferably in one line.
Using
let data = tgSh.getDataRange().getValues();
data.splice(0, headers.getRow());
...works fine but combining the two lines as:
let data = tgSh.getDataRange().getValues().splice(0, headers.getRow());
...just returns the spliced values and not a mutated data
array.
Is there anyway to do this? Not the end of the world but just learning as I go
CodePudding user response:
Use slice()
. It doesn't mutate, it returns a new array. Butince you no longer have a reference to the original array, you can't tell the difference (except for some extra memory allocation, which will be collected quickly by GC).
let data = tgSh.getDataRange().getValues().slice(0, headers.getRow());