我對(duì)JavaScript相當(dāng)陌生,可能需要一些幫助來解決以下問題:即,使用數(shù)組作為要從數(shù)據(jù)中刪除/過濾的項(xiàng)目的輸入,在Google Apps腳本中過濾我的數(shù)據(jù)。如何正確地做到這一點(diǎn),多虧了@Cooper的幫助,他們?cè)谝韵戮€程中提供了正確的答案:根據(jù) Google Apps 腳本中的另一個(gè)數(shù)組過濾數(shù)組但是,這很重要,我不僅想在完全匹配上過濾我的數(shù)據(jù),還想在廣泛的匹配上過濾我的數(shù)據(jù)。下面的代碼確實(shí)可以正確篩選我的數(shù)據(jù),但只排除完全匹配。例如,如果我的數(shù)組包含“red”,則排除所有帶有單詞“red”的行。這是個(gè)好消息。但是,例如,帶有“紅酒”的行仍然保留在我的數(shù)據(jù)集中。這就是我想改變的。toExclude我正在處理的數(shù)據(jù)如下所示,下面指定了一些要過濾/刪除的示例項(xiàng):function main() {// create some example data.var data = [ [ 3, 15, 52 ], [ 'red wine', 18, 64 ], [ 'blue', 11, 55 ], [ 'shoes', 9, 18 ], [ 'car door', 7, 11 ], [ 50, 34, 30 ], [ 'house party', 10, 17 ], [ 'party', 12, 13 ], [ 'cheap beer', 30, 15 ] ];// define filtered items.var toExclude = [ 3, 'red', 'door', 'party', '' ];// run the filter provided by @Cooper. var d=0; for(var i=0;i-d<data.length;i++) { for(var j=0;j<data[i-d].length;j++) { if(toExclude.indexOf(data[i-d][j])!=-1) { data.splice(i-d++,1);//remove the row and increment the delete counter break;//break out of inner loop since row is deleted } } } console.log(data);}以下是我的輸出應(yīng)該是什么樣子的:// how the output actually looks. [ [ 'red wine', 18, 64 ], // supposed to be filtered out since 'red' is included. [ 'blue', 11, 55 ], [ 'shoes', 9, 18 ], [ 'car door', 7, 11 ], [ 50, 34, 30 ], [ 'house party', 10, 17 ], // supposed to be filtered out since 'party' is included. [ 'cheap beer', 30, 15 ] ]// how it should look. [[ 'blue', 11, 55 ], [ 'shoes', 9, 18 ], [ 'car door', 7, 11 ], [ 50, 34, 30 ], [ 'cheap beer', 30, 15 ] ]有誰知道如何解決我的問題?我知道問題出在命令的工作方式上。具體來說,我檢查以前定義的變量是否是我的數(shù)據(jù)的一部分,從而僅刪除輸出為TRUE的行,這僅在發(fā)生完全匹配時(shí)才刪除。我該如何改變這一點(diǎn)?我知道使用單個(gè)輸入是可能的,但不能將此邏輯應(yīng)用于上面這個(gè)相當(dāng)復(fù)雜的代碼。toExclude
查看完整描述