JS知識(shí)

知識(shí)點(diǎn)一:

 JS數(shù)據(jù)類型 : undefined 未定義類型  blooean 布爾類型 null 空類型 number 數(shù)字類型 string 字符串類型 (五種基本類型)     object  對(duì)象類型 (一種復(fù)雜類型)

知識(shí)點(diǎn)二:

 typeof檢測(cè)數(shù)據(jù)類型返回值:undefined  string  number  blooean  object  Function;(六個(gè))

知識(shí)點(diǎn)三:

轉(zhuǎn)化為布爾值為fasle的值:0  " "  false null NaN  undefined;  (六個(gè))

知識(shí)點(diǎn)四:

數(shù)組的創(chuàng)建方式:
var arr= [1,2,3,4,5]; 
console.log(arr);   // [1,2,3,4,5]   (length長(zhǎng)度為5;)
var Array=[1,2,3,4,5];
console.log(Array)  // [1,2,3,4,5] 
var arr =new  Array ("1,2,3,4,5");
console.log(arr);   // ["1,2,3,4,5"] 

知識(shí)點(diǎn)五:
獲取隨機(jī)數(shù)
栗子:

獲取 40-100的隨機(jī)數(shù)
function random(n,m){
          var num=m-n+1
          return Math.floor(Math.random()*num+n);
 }
console.log(Math.random(40,100));

if語(yǔ)句的嵌套

 var score =prompt("請(qǐng)輸入您的成績(jī)")
     //判斷輸入的成績(jī)是否合法
     if(isNaN(score) || score<0 || score>100){
        alert("您輸入的成績(jī)不是一個(gè)數(shù)或者輸入的成績(jī)有誤")

     }else{
        //如果執(zhí)行else則輸入的成績(jī)是合法的
         //繼續(xù)進(jìn)行對(duì)成績(jī)的段位判斷
        if(score<60){
            alert("您的成績(jī)不及格");
         }else if(score<90){
             alert("你的成績(jī)?yōu)榧案?);
         }else if(score<100){
             alert("您的成績(jī)?yōu)閮?yōu)秀");
         }else("您的成績(jī)?yōu)闈M分");
     }

定時(shí)器

設(shè)置定時(shí)器
   var timer = setInterVal(執(zhí)行功能時(shí)間(毫秒));
清除定時(shí)器
     clearInterval(timer);
     timer = null;
     var i =0;
     var timer =setInterval(function(){
         //每秒執(zhí)行一次
        i++;
        console.log(i);
         if (i === 5) {
     clearInterval(timer);
    timer = null;
     }
  },1000)

字符串轉(zhuǎn)數(shù)組

var str = 'hello',轉(zhuǎn)為數(shù)組['h','e','l','l','o']
      var add =str.split("")
      console.log(add);  ["h","e","l","l","o"];

var arr = [1,3,5,6,7,89,4,2],使用splice方法,刪掉3;

var arr = [1,3,5,6,7,89,4,2]
var a =arr.splice(1,1);
console.log(arr); [1,5,6,7,89,4,2]
console.log(a);  [3]

push返回新數(shù)組的長(zhǎng)度

var ary = ['a','b','c'];
var res = ary.push('d','e'); 
console.log(ary);  // ["a", "b", "c", "d", "e"]console.log(res);  // 5

pop返回被刪除的項(xiàng)

var ary = ['1','2','3'];
var res = ary.pop();
console.log(ary);  // ['1','2']console.log(res);  // 3
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容