Posted By

vetri02 on 07/27/11


Tagged

splitarray


Versions (?)

Adds number to each word in a sentence


 / Published in: JavaScript
 

This function adds number to each word in a sentence.

  1. function splitWordNumero(bar){
  2. var foo = bar;
  3. //var foo = "The quick brown fox jumps over the lazy dog";
  4. var temp = [];
  5. var res = [];
  6.  
  7. temp = foo.split(' ');
  8. var j = temp.length;
  9.  
  10. console.log(j);
  11.  
  12. for(i=0; i<j ; i++) {
  13. res.push(temp[i]+(i+1));
  14. }
  15.  
  16. var ans = res.join(' ');
  17.  
  18. //console.log(res.toString());
  19. console.log (ans);
  20. document.getElementById('hello').innerHTML = ans;
  21.  
  22. }
  23. //pasws value here
  24. splitWordNumero("The quick brown fox jumps over the lazy dog");

Report this snippet  

You need to login to post a comment.