Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Initialise and mutate array in one line

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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());
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!