Force JS replace to work on all occurrences of needle

When manipulating strings in JavaScript a useful method to know about is the replace() method. It take 2 parameters – the needle and the haystack. So if you wanted to replace ‘cat’ with ‘dog’ it might look something like this: var myString = “The cat jumped over the fence”; var myNewString = myString.replace(“cat”,”dog”); document.write(myNewString); Great it worked.… Continue reading Force JS replace to work on all occurrences of needle