iterate over an array every x spots and replace with letter? - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

iterate over an array every x spots and replace with letter?

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(){/*w  ww . ja  v a 2 s .  com*/
function weave(word,numSkip) {
    var arr = word.split("");
    for(var i = 0; i < arr.length; i++)
    {
        if((i+1) % numSkip == 0) {
            arr[i] = "x";
        }
    }
    return arr.join("");
}
console.log(weave("weave this is a test",2));
    }

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

Related Tutorials