y18进修笔记1

  // for 
  var arr = ['赵', '钱', '孙', '李'];
  for (var i = 0; i < arr.length; i++) {
    console.log(arr[i]);
  }
  var obj = { name: 'list', age: 26, area: 'bj' };
  for (var j in obj) {
    console.log(j + ' ~ ' + obj[j]);
  }
  
  
  // obj 
  var str = 'hello world';
  console.log(str);// hello world
  console.log(str.length);// 11
  console.log(str.substr(2, 3));// llo截取从第二位以后的三位
  console.log(str.split());// ["hello world"]
  console.log(str.split(''));// ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"]
  console.log(str.split(' '));// ["hello", "world"]
  var arr = ['赵', '钱', '孙', '李'];
  console.log(arr.join());// 赵,钱,孙,李
  console.log(arr.join(''));// 赵钱孙李
  console.log(arr.join('-'));// 赵-钱-孙-李
  
  
  
  // js内置对象
  // str
  var str = 'helloworld';
  console.log(str.indexOf('he'));// 0 返回指定字符串的位置
  console.log(str.indexOf('a'));// -1 没找到
  console.log(str.length);// -1 没找到
  console.log(str.concat('!'));// 字符串拼接
  console.log(str.replace('ll', 'LL'));// heLLoworld
  console.log(str.toUpperCase());//   HELLOWORLD
  console.log(str.toUpperCase().toLowerCase());// helloworld
  // Date
  var dt = new Date();
  console.log(dt.getYear());// 平常用getFullYear
  console.log(dt.getFullYear()); // xxxx
  console.log(dt.getMonth());// 0-11
  console.log(dt.getDate());// 1-31 the day of the month
  console.log(dt.getDay());// 0-6 the day of the week
  console.log(dt.getHours());// 0-23
  console.log(dt.getMinutes());// 0-59
  console.log(dt.getSeconds());// 0-59
  console.log(dt.getMilliseconds());// 0-999
  // Math 类的静态要领 不须要new 须要new的是对象要领
  console.log(Math.random());// [0, 1)
  console.log(Math.random() * 5 + 5);// [5, 10)
  console.log(Math.ceil('2.6'));// 3
  console.log(Math.floor('2.6'));// 2 
  console.log(Math.round('2.6'));// 3 四舍五入
  console.log(Math.sqrt(3 * 3));// 3
  console.log(Math.min(1, 2));// 1
  console.log(Math.max(1, 2));// 2
  console.log(Math.pow(7, 2));// 7*7
  // arr 
  var arr = [];
  conlsole.log(arr.length);// 
  conlsole.log(arr.concat());// 
  conlsole.log(arr.join());// 
  conlsole.log(arr.pop());// 
  conlsole.log(arr.push());// 
  conlsole.log(arr.shift());// 
  conlsole.log(arr.unshift());// 
  conlsole.log(arr.sort());// 
  conlsole.log(arr.reverse());// 
  conlsole.log(arr.slice);// charu
  conlsole.log(arr.splice());// del
  
  
  
  // 浏览器window对象
  // window.alert();
  // window.confirm();
  console.log(window.navigator);
  console.log(window.navigator.cookieEnabled);
  console.log(window.location);
  console.log(window.location.search);// ?id=2
  console.log(window.history);
  // console.log(window.history.forward());
  // console.log(window.history.go());
  console.log(window.screen);
  console.log(window.screen.width);
  console.log(window.screen.availHeight);
  console.log(window.document);
  
  
  
  
  // var的重要性 不声明污染全局union
  window.str = 'union';
  function t1() {
    var str = 'china';
    function t2() {
      var str = 'japan';
      // alert(str);
    }
    t2();
  }
  t1();
 
 
    原文作者:幸运儿
    原文地址: https://segmentfault.com/a/1190000007247838
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞