Essential Javascript Techniques


/ Published in: JavaScript
Save to your folder(s)

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!


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.