资讯专栏INFORMATION COLUMN

y18学习笔记1

mingzhong / 2961人阅读

摘要:赵钱孙李截取从第二位之后的三位赵钱孙李赵钱孙李赵钱孙李赵钱孙李内置对象返回指定字符串的位置没找到没找到字符串拼接一般用类的静态方法不需要需要的是对象方法四舍五入浏览器对象的重要性不声明污染全局

</>复制代码

  1. // for
  2. var arr = ["赵", "钱", "孙", "李"];
  3. for (var i = 0; i < arr.length; i++) {
  4. console.log(arr[i]);
  5. }
  6. var obj = { name: "list", age: 26, area: "bj" };
  7. for (var j in obj) {
  8. console.log(j + " ~ " + obj[j]);
  9. }
  10. // obj
  11. var str = "hello world";
  12. console.log(str);// hello world
  13. console.log(str.length);// 11
  14. console.log(str.substr(2, 3));// llo截取从第二位之后的三位
  15. console.log(str.split());// ["hello world"]
  16. console.log(str.split(""));// ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"]
  17. console.log(str.split(" "));// ["hello", "world"]
  18. var arr = ["赵", "钱", "孙", "李"];
  19. console.log(arr.join());// 赵,钱,孙,李
  20. console.log(arr.join(""));// 赵钱孙李
  21. console.log(arr.join("-"));// 赵-钱-孙-李
  22. // js内置对象
  23. // str
  24. var str = "helloworld";
  25. console.log(str.indexOf("he"));// 0 返回指定字符串的位置
  26. console.log(str.indexOf("a"));// -1 没找到
  27. console.log(str.length);// -1 没找到
  28. console.log(str.concat("!"));// 字符串拼接
  29. console.log(str.replace("ll", "LL"));// heLLoworld
  30. console.log(str.toUpperCase());// HELLOWORLD
  31. console.log(str.toUpperCase().toLowerCase());// helloworld
  32. // Date
  33. var dt = new Date();
  34. console.log(dt.getYear());// 一般用getFullYear
  35. console.log(dt.getFullYear()); // xxxx
  36. console.log(dt.getMonth());// 0-11
  37. console.log(dt.getDate());// 1-31 the day of the month
  38. console.log(dt.getDay());// 0-6 the day of the week
  39. console.log(dt.getHours());// 0-23
  40. console.log(dt.getMinutes());// 0-59
  41. console.log(dt.getSeconds());// 0-59
  42. console.log(dt.getMilliseconds());// 0-999
  43. // Math 类的静态方法 不需要new 需要new的是对象方法
  44. console.log(Math.random());// [0, 1)
  45. console.log(Math.random() * 5 + 5);// [5, 10)
  46. console.log(Math.ceil("2.6"));// 3
  47. console.log(Math.floor("2.6"));// 2
  48. console.log(Math.round("2.6"));// 3 四舍五入
  49. console.log(Math.sqrt(3 * 3));// 3
  50. console.log(Math.min(1, 2));// 1
  51. console.log(Math.max(1, 2));// 2
  52. console.log(Math.pow(7, 2));// 7*7
  53. // arr
  54. var arr = [];
  55. conlsole.log(arr.length);//
  56. conlsole.log(arr.concat());//
  57. conlsole.log(arr.join());//
  58. conlsole.log(arr.pop());//
  59. conlsole.log(arr.push());//
  60. conlsole.log(arr.shift());//
  61. conlsole.log(arr.unshift());//
  62. conlsole.log(arr.sort());//
  63. conlsole.log(arr.reverse());//
  64. conlsole.log(arr.slice);// charu
  65. conlsole.log(arr.splice());// del
  66. // 浏览器window对象
  67. // window.alert();
  68. // window.confirm();
  69. console.log(window.navigator);
  70. console.log(window.navigator.cookieEnabled);
  71. console.log(window.location);
  72. console.log(window.location.search);// ?id=2
  73. console.log(window.history);
  74. // console.log(window.history.forward());
  75. // console.log(window.history.go());
  76. console.log(window.screen);
  77. console.log(window.screen.width);
  78. console.log(window.screen.availHeight);
  79. console.log(window.document);
  80. // var的重要性 不声明污染全局union
  81. window.str = "union";
  82. function t1() {
  83. var str = "china";
  84. function t2() {
  85. var str = "japan";
  86. // alert(str);
  87. }
  88. t2();
  89. }
  90. t1();

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/91026.html

相关文章

  • react源码解析004 - 关于类型检查工具flow

    摘要:简介是推出的类型检查工具。使得咱们可以指定变量的类型,避免此类错误的发生。停用后台进程,使用以上示例的源码。配置文件这部分将结合的和官方文档进行解析。一个文件简称,就类似于中的头文件,是用来定义跨项目可用的全局变量。 Flow 简介 flow是facebook推出的js类型检查工具。js是一门弱类型语言,没有从语言层面去保证变量类型不匹配的基本错误。flow使得咱们可以指定变量的类型,...

    huayeluoliuhen 评论0 收藏0
  • ApacheCN 人工智能知识树 v1.0

    摘要:贡献者飞龙版本最近总是有人问我,把这些资料看完一遍要用多长时间,如果你一本书一本书看的话,的确要用很长时间。为了方便大家,我就把每本书的章节拆开,再按照知识点合并,手动整理了这个知识树。 Special Sponsors showImg(https://segmentfault.com/img/remote/1460000018907426?w=1760&h=200); 贡献者:飞龙版...

    刘厚水 评论0 收藏0
  • 【LNMPR源码学习笔记汇总

    摘要:此文用于汇总跟随陈雷老师及团队的视频,学习源码过程中的思考整理与心得体会,此文会不断更新视频传送门每日学习记录使用录像设备记录每天的学习源码学习源码学习内存管理笔记源码学习内存管理笔记源码学习内存管理笔记源码学习基本变量笔记 此文用于汇总跟随陈雷老师及团队的视频,学习源码过程中的思考、整理与心得体会,此文会不断更新 视频传送门:【每日学习记录】使用录像设备记录每天的学习 PHP7...

    Barrior 评论0 收藏0

发表评论

0条评论

mingzhong

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<