编程编码 小tips~~~

//精确计算,日期+循环
var start=new Date().getTime();
do{
    var end=new Date().getTime();
}
while(end-start<2000);
console.log("上段代码"+(end-start)+"毫秒");

时间的精确计算~~可以用于一些小Demo的测试

//返回介于0到1之间一个随机数,不包括0和1。

//值=Math.floor(Math.random()*(最后一个值-第一个值+1)+第一个值)


  function select(start,end) {    
      var total=end-start+1;    
      return Math.floor(Math.random()*total+start);
  }

返回随机数

//随机生成不重复的数组
var num=5;
var arr=[];
function select(start,end){
    var total=end-start+1;
    return Math.floor(Math.random()*total+start);
}

while(num>0){
    var randomNumber=select(1,100);
   if(arr.indexOf(randomNumber)===-1){
       arr.push(randomNumber);
       num--;
   }
}
console.log(arr);
typeof Symbol()    //"symbol" 

  typeof Number()    //"number" 

  typeof String()    //"string" 

  typeof Function()    //"function" 

  typeof Object()    //"object" 

  typeof Boolean()    //"boolean" 

  typeof null    //"object" 

  typeof undefined    //"undefined" 

 //改变原数组的方法 : push,pop,unshift,shift,reverse,sort,splice

猜你喜欢

转载自www.cnblogs.com/lianer88/p/9952225.html
今日推荐