Javascript examples for String Operation:String Replace
Replace random chars in a string in javascript
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <script type="text/javascript"> var ctu = [],s = "this is a test this is a test.", newstring=" "; ctu[0]="A";/*w w w .j a v a2 s.co m*/ ctu[1]="B"; ctu[2]="C"; var s = s.split(" "); for(var i = 0;i<s.length;i++){ s[i]=ctu[Math.floor(Math.random() * ctu.length)]; newstring += s[i] + " "; } document.write(newstring); </script> </body> </html>