The replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular expression.
The replace () method has two parameters, the first parameter is a regular expression, and the regular expression, if with the global flag/g, represents the replacement of all matching strings, or only the first matching string is replaced.
The second argument can be a string, or it can be a function. $, $ ... represents text that matches a regular expression.
There is many ways we can make a difference. Global change starts with you. Sign up for our free newsletter today.
Output: There is many Ways We Can make A difference. Global change starts with you. Sign up for our free Newsletter Today.
The source code is as follows:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"Content= "text/html; charset=utf-8;">5 <title>JS Replace method</title>6 <Metaname= "Author"content= "Rainna" />7 <Metaname= "keywords"content= "Rainna S js Lib" />8 <Metaname= "description"content= "JS Replace method" />9 </Head>Ten <Body> One <H1>Use the JS replace () method to capitalize the first letter of all words</H1> A <P>The replace () method is used to replace other characters with some characters in a string, or to replace a substring that matches a regular expression.<BR/>The replace () method has two parameters, the first parameter is a regular expression, and the regular expression, if with the global flag/g, represents the replacement of all matching strings, or only the first matching string is replaced.<BR/> -The second argument can be a string, or it can be a function. $, $ ... represents text that matches a regular expression.</P> - <PID= "word">There is many ways we can make a difference. Global change starts with you. Sign up for our free newsletter today.</P> the <ahref=""ID= "Replacebtn">Replace</a> - - <Script> - varReplacefunc= function(){ + varWord=document.getElementById ('Word'). Innertext.tostring (), - btn=document.getElementById ('replacebtn'); + A varfunc1= function(str) { at returnStr.replace (/\b\w+\b/G,function(word) { - returnword.substring (0,1). toUpperCase ()+word.substring (1); - }); - } - - Btn.onclick= function(event) { in Event.preventdefault (); - Console.log (func1 (Word)); to } + } - the Replacefunc (); * </Script> $ </Body>Panax Notoginseng </HTML>