Skip to content
Advertisement

Get the values of particular columns and filter on a particular column – Google Apps Script

I have this script

JavaScript

This is a filter script. In this filter is getting value from source in the range A:G, but i need to get only Column B, Column D, Column F, Column G

How to avoid getting filtered Column A,C,E?

Advertisement

Answer

Explanation:

One way to select particular columns is to use the map function.

  • The following will get columns b,d,f,g from the range A:G.

    const rawData = ss.getRange("A:G").getValues().map(([,b,,d,,f,g]) => [b,d,f,g]);

Don’t use a for loop to filter on a particular column.

It is way more efficient to use filter to filter on a particular column. You haven’t specified in your question for which column you want to filter on. Assuming the new data will consist of columns b,d,f,g the column indexes for the raw data will be 0,1,2,3.

For example:

const frawData=rawData.filter(row=>row[3]=="User missing");

this will filter on column g since we have removed a,c,e and column g is in 3rd position (starting from 0). If you want to filter on a different column. Choose 0 for b, 1 for d, 2 for f and 3 for g.

Solution:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement