国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

javaScript Array(數組)相關方法簡述

2024-05-06 14:14:39
字體:
來源:轉載
供稿:網友
1.創建Array對象(賦初值情況下)兩種方法:
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:獲取數組長度
3.toString():輸出數組中的所有元素。
alert(aColor.toString());////output: red,black,yellow
4.valueOf():同3
5.join():連接數組值,將數組通過連接符連接,返回鏈接后的字符串
eg.alert(aColor.join("->"));//output:red->black->yellow
//(string)6.split():將字符串分割為字符數組,其中split(" ")將字符串分割為單個字符數組,eg."str"分割為s,t,r
7.contact():將參數附加到數組末尾,返回的函數值是新的Array對象
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():返回具有指定項的新數組。
9.push()/pop():push()在數組結尾添加一個項,pop()刪除最后一個數組項并將該項值返回。
eg.
var aColor=new Array('red','black','yellow');
aColor.push("blue");
aColor.push("white");
alert(aColor.toString());
aColor.pop();
alert(aColor.toString());
10.shift():刪除數組中第一個項
11.unshift():向數組添加第一項,其他的各項后移。
var aColor=new Array('red','black','yellow');
aColor.shift();
alert(aColor.toString());
aColor.unshift("red");
alert(aColor.toString());
12.reverse():顛倒數組項的順序。
13.sort():對數組項升序排序。
eg.
var aColor=new Array('red','black','yellow');
aColor.sort();
alert(aColor);
alert(aColor.reverse());
14.splice().
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 呼图壁县| 曲周县| 大化| 瓦房店市| 平泉县| 潞西市| 儋州市| 南召县| 花莲县| 牟定县| 穆棱市| 凤庆县| 化隆| 夏邑县| 施甸县| 晴隆县| 满洲里市| 吉水县| 兴安盟| 鸡西市| 会宁县| 西乌| 登封市| 遵化市| 博兴县| 葫芦岛市| 小金县| 阿巴嘎旗| 安达市| 泰安市| 永胜县| 伽师县| 射洪县| 南江县| 巫山县| 开平市| 阜阳市| 永川市| 清原| 如皋市| 云南省|