简体   繁体   中英

How can I make a JS filter work in the Apps Script API?

I am trying to use a filter in order to delete some unnecessary data in the fastest possible way.

Unfortunately, I am getting a syntax error in the script editor when trying to save the following code:

function deleteRows(dataRange){

        var formated = dataRange.filter(e => e[8]||e[9]||e[10]||e[11]||e[12]||e[13]||e[14]||e[15]||e[16]||e[17]||e[18]||e[19]);

     return formated;
    }   

Does anyone know how can I make the above code work in apps scripts? Or if the code can't work, what would be the alternative... I am out of ideas...

Google Apps Script is at ES 5.1 level, so it has no ES6 features like arrow functions, sets, etc. But the modification is straightforward:

function deleteRows(dataRange){
  var formatted = dataRange.filter(function(e) {
    return e[8]||e[9]||e[10]||e[11]||e[12]||e[13]||e[14]||e[15]||e[16]||e[17]||e[18]||e[19];
  });
 return formatted;
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM