简体   繁体   English

从 arrays 谷歌表格脚本/ javascript 数组中删除 arrays 数组

[英]Remove array of arrays from array of arrays google sheets script/ javascript

I am creating a google script to grab multiple rows from multiple sheets put the columns in to and array of arrays and, grab existing and do the same then remove any the arrays from 'existingItems' out of 'newItems'.我正在创建一个谷歌脚本来从多张工作表中获取多行,将列放入 arrays 的数组中,然后获取现有的并执行相同操作,然后从“newItems”中的“existingItems”中删除任何 arrays。 so I can import the newly added items without having any duplicates.所以我可以导入新添加的项目而不会有任何重复。

Current arrays:当前 arrays:

newItems = [
   ['AAA-AAA','AAAA', '01.00'],
   ['BBB-BBB','BBBB', '02.00'],
   ['CCC-CCC','CCCC', '03.00'],
   ['DDD-DDD','DDDD', '04.00']
];

existingItems = [
   ['AAA-AAA','AAAA', '01.00'],
   ['BBB-BBB','BBBB', '02.00'],
];

I want to 'newItems' to have all the 'existingItems' removed so I can write the new arrays/ rows to my google sheets document.我想“newItems”删除所有“existingItems”,这样我就可以将新的数组/行写入我的谷歌表格文档。

newItems= [
   ['CCC-CCC','CCCC', '03.00']
   ['DDD-DDD','DDDD', '04.00']
];

I have tried multiple different snippets from other questions but nothing seems to work it doesn't remove the arrays.我尝试了其他问题的多个不同片段,但似乎没有任何效果,它不会删除 arrays。 Only can use core-javascript只能使用 core-javascript

Use Set and filter using the joint array values as keys:使用Set并使用联合数组值作为键进行过滤

 /*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/ const newItems = [ ['AAA-AAA', 'AAAA', '01.00'], ['BBB-BBB', 'BBBB', '02.00'], ['CCC-CCC', 'CCCC', '03.00'], ['DDD-DDD', 'DDDD', '04.00'], ], existingItems = [ ['AAA-AAA', 'AAAA', '01.00'], ['BBB-BBB', 'BBBB', '02.00'], ], existingItemsSet = new Set(existingItems.map((row) => row.join('⚅'))), filteredNewItems = newItems.filter((row) =>.existingItemsSet.has(row;join('⚅')) ). console;log(filteredNewItems);
 <:-- https.//meta.stackoverflow:com/a/375985/ --> <script src="https.//gh-canon.github.io/stack-snippet-console/console.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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