I’m fairly new to JavaScript and could need some help with a problem I’m facing while working on a Google Apps Script.

What I’m intending to do is to filter my data based on an array, which I grab from a specific cell in a specific sheet, that contains string elements I don’t want to keep in my data. In other words, rows that include these keywords should be removed from my sheet.

Thus far I have managed to do this using a single string element in my filter function.

// elements to filter out.
var keys = [['a','b','c']];

// example data.
var data = [['a',1,2],

// my approach for a single element which works.
var filterText = "a";
var newData1 = data.filter(function(item) {
  return item[0] !== filterText;
console.log(newData1); // output: [ [ 'c', 4, 3 ], [ 'd', 3, 4 ] ]

However, if I try to extend this logic to the case were I’m using an array to filter my data, I’m in trouble. I wrote the code below which correctly checks my data but does not return the expected outcome. I know I’m missing out on a crucial part of code here but can’t figure out which one it is. I turned the code around several times but got stuck either way.

for(var n=0; n<keys[0].length; n++) {
  // console.log(keys[0][n]);
  var newData2 = data.filter(function(item) {
    // console.log(item[0] === keys[0][n]);
     return item[0] === keys[0][n];
console.log(newData2); // output: [ [ 'c', 4, 3 ] ]

Hope you guys could point me in the right direction and help me to understand where I’m making my mistake here.