(1)Array:
方法1:
var aValue = new Array(20);
方法2:
var aValue = new Array();
aValue[0] = "a";
aValue[1] = "b";
...
方法3:
var aValue = new Array("a","b",...)
方法4:
var aValue = ["a","b",...](無需明聲明使用Array類)
aValue.join(參數)方法,把數組各項串連起來,串連符是參數。
aValue = new Array("a","b","c")
aValue.join("-") //輸出 :"a-b-c"
一個逆向的方法是:String.split(參數)方法。把string類型轉換為Array
var sColor = "green";
var aColor = sColor.split("");//得到數組,["g","r","e","e","n"];
Array類的concat()和slice()方法同string類
Array類的push(),pop()方法和unshift(),shift(),方法,分別提供了其類似棧(後進先出LIFO)的行為和類似隊列(先進先出LILO)的行為。
Array_name.reverse() 顛倒數組順序
Array_name.sort() 給數組排序
Array_name.splice()把資料項目插入數組的中部(十分有用且有趣。)
(2)Date:
比較常用的:
var _date = new Date();
var _year = _date.getFullYear(); 當前年
var _month = _date.getMonth(); 當前月
var _day = _date.getDate(); 當前日
alert(_date.toTimeString().split(" ")[0]); 當前時分秒
(3)Global 內建對象
比較特殊,比如isNan(),parseInt()等,都是它的函數。
encodeURI(),encodeURIComponent(),decodeURI() 和decodeURIComponet() 與BOM方法中的escape()和unescape()最大的區別就是,escape()對於非ASCII字元集的符號不編碼,所以,提倡用 encodeURI()來編碼
(4)Math 內建對象
min()
max()
abs()絕對值,
ceil()向上舍入
floor()向下舍入
round()四捨五入
alert(Math.ceil(25.5)); //output 26
alert(Math.floor(25.5));//output 25
alert(Math.round(25.5));//output 26
random() 返回一個0到1之間的隨機數
例如:選擇從1到10的隨機數:
var iNum = Math.floor(Math.random()*10 + 1)