Number類型的幾個方法
1,toFixed()
返回具有指定位元小數的數字
var oValue = new Number(99);
alert(oValue.toFixed(2)) //output 99.00
2,toExponential()
返回用科學計數法表示的數位字串形式
var oValue = new Number(99);
alert(oValue.toExponential(1)); //output 9.9e+1
3,toPrecision()
根據最有意義的形式返回數位預定形式或指數形式
var oValue = new Number(99);
alert(oValue.toPrecision(1)); //output 1e+2
alert(oValue.toPrecision(2)); //output 99
alert(oValue.toPrecision(3)); //output 99.0
以上三個方法都會進行舍入操作。
字串類型的幾個方法:
1,charAt和charCodeAt
訪問字串中的單個字元或字元代碼
var oValue = new String("hello");
alert(oValue.chatAt(1)); //output e
alert(oValue.chatCodeAt(1)); //output 101
2,silce和substring
var oValue = new String("hello world");
alert(oValue.slice(-3)); //output rld
alert(oValue.substring(-3)); //output hello world
alert(oValue.slice(3,-4)); //output lo w
alert(oValue.substring(3,-4)); //output hel
Globald對象
URI方法encodeURI、encodeURIComponent、decodeURI和decodeURIComponent代替了BOM的escape()和unescape()方法。URI方法更可取,因為它們會對所有Unicode符號變嗎,而BOM方法只能對ASCII符號正確編碼。盡量避免使用escape()和unescape()方法。