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

267
Views
How to remove multiple elements from arrays of an array using GAS?

The problem

I have a dataset encompassing empty columns. This dataset is obtained by getValues() of a defined range. Since I'll be storing this data set, I'd like to remove empty columns prior to that and, therefore, these columns need to be removed.

Dataset Sample

[
["120/1","2022-02-01T03:00:00.000Z","2022-02-01T03:00:00.000Z","Cartão Crédito","","Sicredi","","Visa","","1 + 6x","","1 de 7",100],
["120/2","2022-02-01T03:00:00.000Z","2022-03-01T03:00:00.000Z","Cartão Crédito","","Sicredi","","Visa","","1 + 6x","","2 de 7",100]
]

The evil code snippet (to me)

const colsVazias = [11, 9, 7, 5];//"Columns/elements" to be removed
    for (let i = colsVazias.length - 1; i >= 0; i--) {
      for (let r = 0; r < pagtos.length; r++) {
        pagtos[r].splice(colsVazias[i], 1)
      }
    }

I have also tried this one (borrowed from @nnnnnn), but I can't tweak it to meet the demand here. Most likely, because we're dealing with different dimensions here...

var valuesArr = ["v1","v2","v3","v4","v5"],
    removeValFromIndex = [0,2,4];    

for (var i = removeValFromIndex.length -1; i >= 0; i--)
   valuesArr.splice(removeValFromIndex[i],1);

Expected output:

[
["120/1","2022-02-01T03:00:00.000Z","2022-02-01T03:00:00.000Z","Cartão Crédito","Sicredi","Visa","1 + 6x","1 de 7",100],
["120/2","2022-02-01T03:00:00.000Z","2022-03-01T03:00:00.000Z","Cartão Crédito","Sicredi","Visa","1 + 6x","2 de 7",100]
]

Appreciate any help!

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

0

A simple map/filter combo would do it

let pagatos = [
["120/1","2022-02-01T03:00:00.000Z","2022-02-01T03:00:00.000Z","Cartão Crédito","","Sicredi","","Visa","","1 + 6x","","1 de 7",100],
["120/2","2022-02-01T03:00:00.000Z","2022-03-01T03:00:00.000Z","Cartão Crédito","","Sicredi","","Visa","","1 + 6x","","2 de 7",100]
];

let remove = [10, 8, 6, 4]
pagatos = pagatos.map(p => p.filter((v,i) => !remove.includes(i)))
console.log(pagatos)

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!