通过Google Apps Script创建一个不包含在Google Sheets列中的值的列表 &



我的尝试是与filter + includes:

function not_contains() {
var new_opt = [['a'],['b'],['d']];
var col_g = SpreadsheetApp.getActive().getSheetByName('test_stack').getRange('G1:G').getValues();
// [['a'],['b'],['c'],[''],['']]
var not_match = new_opt.filter(x => !col_g.includes(x));
}

实际结果:

[ [ 'a' ], [ 'b' ], [ 'd' ] ]

预期结果:

[ [ 'd' ] ]

因为它是一个2D数组,并且includes只直接比较原语#字符串,而不是数组对象,所以使用array。一个数组:

const col_g_flat = col_g.flat();//// ['a','b','c',..]
const not_match = new_opt.filter(x => !col_g_flat.includes(x/*access the string inside*/[0]));

最新更新