javascript基本封裝類型

來源:互聯網
上載者:User

標籤:javascript   基本封裝類型   

①Number類型

 

Number類型有一些靜態屬性(直接通過Number調用的屬性,無需new運算子)和方法.

 

 

//var box = 1000.789;//alert(box.toString());//轉換成字串,傳參可以轉換進位//alert(box.toLocaleString());//本地形式,1,000.789//alert(box.toFixed(2));//1000.79,保留兩位小數,四捨五入//alert(box.toExponential());//指數形式,1.000789e+3//alert(box.toPrecision(8));//1.00e+3,指數或點形式,根據參數來選擇

②String類型

//var box = 'aAabaaBbq';//alert(box.charAt(1));//A//alert(box.charCodeAt(2));//A,97,返回的是acssii碼//alert(box[0]);//alert(box.concat('is','ddd'));//參數字串串連//alert(box.slice(4,6));//aa//alert(box.substring(4,6));//aa//alert(box.substring(-4));//負數返回全部//alert(box.substr(4,6));//aaBbq//alert(box.substr(4,-4));//第二參數為負數,直接轉0//alert(box.substr(-4));//aBbq,9+(-4)=5位開始 

//var box ='asbdfghjkla';//alert(box.indexOf('b'));//2,返回b的索引值//alert(box.indexOf('d',2));//3//alert(box.lastIndexOf('a'));//10//alert(box.lastIndexOf('a',9));//0,從指定的位置向前搜尋
 

/*沒有找到返回-1,樣本:找出全部a*///var box ='asbdfghjkla';//var boxarr =[];//存放a位置的數組//var pos =box.indexOf('a');//擷取第一個a的位置//while (pos > -1){//大於-1,說明存在a//    boxarr.push(pos);//添加到數組//    pos = box.indexOf('a', pos +1);//重新賦值pos目前的位置//}//alert(boxarr);//0,10


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

javascript基本封裝類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.