欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javaScript Array(數(shù)組)相關(guān)方法簡述

 更新時(shí)間:2009年07月25日 13:58:12   作者:  
javaScript Array(數(shù)組)相關(guān)方法簡述,讓大家更快的熟悉array數(shù)組的用法。
1.創(chuàng)建Array對(duì)象(賦初值情況下)兩種方法:
var aColor=new Array('red','black','yellow');
alert(aColor.toString());//output: red,black,yellow
var aColor=['red','black','blue'];
alert(aColor.toString());//output: red,black,blue
2.length:獲取數(shù)組長度
3.toString():輸出數(shù)組中的所有元素。
alert(aColor.toString());////output: red,black,yellow
4.valueOf():同3
5.join():連接數(shù)組值,將數(shù)組通過連接符連接,返回鏈接后的字符串
eg.alert(aColor.join("->"));//output:red->black->yellow
//(string)6.split():將字符串分割為字符數(shù)組,其中split(" ")將字符串分割為單個(gè)字符數(shù)組,eg."str"分割為s,t,r
7.contact():將參數(shù)附加到數(shù)組末尾,返回的函數(shù)值是新的Array對(duì)象
eg.
var aColor=new Array('red','black','yellow');
var aColorCon=aColor.concat("1","2");
alert(aColorCon.toString());//output: red,black,yellow,1,2
8.slice():返回具有指定項(xiàng)的新數(shù)組。
9.push()/pop():push()在數(shù)組結(jié)尾添加一個(gè)項(xiàng),pop()刪除最后一個(gè)數(shù)組項(xiàng)并將該項(xiàng)值返回。
eg.
var aColor=new Array('red','black','yellow');
aColor.push("blue");
aColor.push("white");
alert(aColor.toString());
aColor.pop();
alert(aColor.toString());
10.shift():刪除數(shù)組中第一個(gè)項(xiàng)
11.unshift():向數(shù)組添加第一項(xiàng),其他的各項(xiàng)后移。
var aColor=new Array('red','black','yellow');
aColor.shift();
alert(aColor.toString());
aColor.unshift("red");
alert(aColor.toString());
12.reverse():顛倒數(shù)組項(xiàng)的順序。
13.sort():對(duì)數(shù)組項(xiàng)升序排序。
eg.
var aColor=new Array('red','black','yellow');
aColor.sort();
alert(aColor);
alert(aColor.reverse());
14.splice().

相關(guān)文章

最新評(píng)論