Search and Replace in a String - Javascript String

Javascript examples for String:replace

Description

Search and Replace in a String

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*www  . j a  v  a  2s  .  co m*/
console.log(findAndReplace("field", 'fd'));
console.log(findAndReplace("grass", 'gs'));
function findAndReplace(a, b) {
    return b.split("").reduce(function(a, s) {
        return a.replace(s, '');
    }, a);
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials