I’m looking for a way to possibly search for values that are inside of an array – that are themselves within an object – by using regex. This is because the values within the arrays will be strings.
I have found some information about nested arrays but I don’t see this being a good solution here as you would need to know the indices. My plan is to let the regex function search for strings within the array
const objectOfArrays = {
array1: ["string", "string", "string",],
array2: ["string", "string", "string",],
array3: ["string", "string", "string",],
array4: ["string", "string", "string",],
};
Up until now I’ve been using this regex pattern with individual variables to match any instance:
const regex = new RegExp(`\b${array1.join("|")}\b`, "i");
The idea is to have one regex pattern to match anything, for example: ${objectOfArrays.array1}
but it’s proving difficult to get a one-fits-all solution.
Any input is appreciated. I realise that some things here are basic but to tie them all together takes some know-how.
Macaylen Exley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3