Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript replace all with variable

/**
*A better method for replacing strings is as follows:
**/
function replaceString(oldString, newString, fullString) {
  return fullS.split(oldS).join(newS)
}
replaceString('World', 'Web', 'Brave New World')//'Brave New Web'
replaceString('World', 'Web', 'World New World')//'Web New Web'
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #replace #variable
ADD COMMENT
Topic
Name
5+7 =