how to write a function to replace in javascript code example Example: javascript replace var res = str.replace("find", "replace");