Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 23x 23x 23x 132x 36x | const filterArrayByQueryMatch = <
T extends Record<string, unknown> | string | any
>(
query: string,
arr: T[] = [],
fields: (keyof T)[] = []
) => {
const regex = new RegExp(query, 'ig');
return arr.filter(item => {
if (typeof item === 'string') return item.match(regex);
return fields.some(field => String(item[field]).match(regex));
});
};
export { filterArrayByQueryMatch };
|