Trying to create a function with replace and variables

Last frustration for tonight i hope :wink:

i created the function below

function findReplace(find,replace,html) {
    html = html.replace( find/g, replace );  //(/blue/gi, "red");
    return html;

where find is a variable
i want to change every time the variable is found
normally with just one word this works with (/blue/g, "red");
but when i replace blue with find the variable becomes fixed... mwaaa
i guess i have to do something with // \ /\ / but no matter what i try i get errors and in google i use or the wrong search tag or there is no answer...

How does this needs to be done?

This should help...

Actually, I don't thing replaceAll is in node yet

Try this...

function replaceAll(str, find, replace) {
  return str.replace(new RegExp(find, 'g'), replace);

I tried that but this gives me this error

"TypeError: payload.replaceAll is not a function"

tried replaceAll() in other projects but allways an error

you are right, thanks i try that!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.