Posted By

alvincrespo on 02/23/10


Tagged

javascript replace String loop for essential substring techniques


Versions (?)

Essential Javascript Techniques


 / Published in: JavaScript
 

These are essential javascript techniques every javascriptr must know. I will be adding more to this list, let me know what you'd like to see. Thanks!

  1. <script type="text/javascript">
  2. //replace a string
  3. var astring = "Peter picked a peck of pickled peppers, how many peppers did Peter Piper pick?";
  4. console.log(astring.replace(/peppers/gi,"parsnips"));
  5.  
  6. //truncate a string
  7. console.log(astring.substr(0,30));
  8.  
  9. //display numbers 0 -> 100 skipping 2
  10. for(var i = 0; i<=100; i+=2){
  11. if(i == 0)
  12. console.log(0);
  13. else
  14. console.log(i-1)
  15. }
  16. </script>

Report this snippet  

You need to login to post a comment.