String Replace All – Javascript

In general JavaScript replace function replaces the first occurrence in the string. It takes two parameters , first parameter to find the string and second parameter is string to replace when it found.

Replace Snippet :

var str = "Javascript find Function";
str = str.replace("find",”replace”);

Replace All Snippet :

var str = "Javascript find Function";
str = str.replace(/find/g,”replace”);

Leave a Reply

Your email address will not be published. Required fields are marked *