There is a row object called 'user' that contains key-value pairs of columns and their values. My goal is to highlight all occurrences of a specific word in that row and then return the updated row within a ReactJS table.
I attempted the following approach, but it did not yield the desired results.
const searched = searchVal;
if (searched !== "") {
Object.entries(user).forEach(([key, value]) => {
if (value.includes(searched))
{
const re = new RegExp(searched, "g");
const newText = value.replace(re, `<mark>${searched}</mark>`);
value = newText;
}
return origData[index];
}
});
}