基本Javascript技术

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基本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>

以上是关于基本Javascript技术的主要内容,如果未能解决你的问题,请参考以下文章

精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解!(转载)

VSCode自定义代码片段12——JavaScript的Promise对象

VSCode自定义代码片段12——JavaScript的Promise对象

30秒就能看懂的JavaScript 代码片段

常用Javascript代码片段集锦

48个值得掌握的JavaScript代码片段(上)