How to replace all occurrences of a string in JavaScript

Replace all occurrences of a string in JavaScript

<script type=”text/javascript”>
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[]\]/g, ‘\$&’); // $& means the whole matched string
}

function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), ‘g’), replace);
}
</script>