使用 lodash 从数组中查找子字符串并将它们推送到另一个,然后将结果与第三个 table 进行比较

use lodash to find substring from array and to push them to another and then to compare result with the 3rd table

我有数组:

all [a,b,ac,d, A]

我想在其中使用来自 lodash 的过滤器找到包含子字符串“a”(“A”)的所有元素,并将它们推送到另一个 - 到 filterTab

   const item = "a"

我这样试:

import { some, method, differenceWith, isEquel } from 'lodash';
const filterTab = [];

filterTab.push (some(all, method('match',/item/i)));

但是不行。

下一步,如果成功了-它将是这样的:

var dif = differenceWith(filterTab, array3, _.isEqual);

而且我不知道为什么它不起作用...

如果您想将 all 中每个匹配 item 的值放入 filterTab 中,然后得到 filterTabarray3 之间的差值,请使用这个例子:

import { filter, difference, method } from 'lodash';

const all = ['a','b','ac','d', 'A'];

const filterTab = [];
const item = 'a';

filterTab.push(...filter(all, method('match', new RegExp(item, 'i'))));

const diff = difference(array3, filterTab);