Part of my tool allows a user to enter a string into a textfield, check if any words entered match with a preset array.
If the user's string contains a name object in the array then I want it to be replaced with a link.
I've created the function and onClick it should get the user's content, loop through the array to see if any names match the user's content and then replace that name with a link.
Currently, it's only doing it per array object where as I need it to replace all and only return one string.
const generateContent = () => {
var arr1 = [{
link: 'https://www.link1.com/',
name: 'Link1'
}, {
link: 'https://www.link2.com/',
name: 'Link2'
}];
const findArrayItem = arr1.find(obj => content.includes(obj.name))
const final = content.replaceAll(findArrayItem.name, "<a href=" + findArrayItem.link + ">" + findArrayItem.name + "</a>")
setFinalContent(final)
}