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

0 javascript testing lodash e2e-testing testcafe

我有数组:

all [a,b,ac,d, A]
Run Code Online (Sandbox Code Playgroud)

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

   const item = "a"
Run Code Online (Sandbox Code Playgroud)

我尝试这样:

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

filterTab.push (some(all, method('match',/item/i)));
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

下一步如果它有效 - 它将是这样的:

var dif = differenceWith(filterTab, array3, _.isEqual);
Run Code Online (Sandbox Code Playgroud)

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

Dmi*_*eev 9

如果你想要把每一个值的匹配itemall进入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);
Run Code Online (Sandbox Code Playgroud)