中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      JavaScript高級程序設(shè)計:本地對象Array

      時間:2024-10-22 05:43:10 JavaScript 我要投稿
      • 相關(guān)推薦

      JavaScript高級程序設(shè)計:本地對象Array

        創(chuàng)建Array對象

        復(fù)制代碼 代碼如下:

        //one

        var aValues=new Array();

        //two

        var aValues=new Array(20);

        //three

        var aColors=new Array();

        aColors[0]="red";

        aColors[1]="green";

        aColors[2]="blue";

        //four

        var aColors=new Array("red","green","blue");

        //five

        var aColors=["red","green","blue"];

        join && split

        join:連接字符串

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue"];

        alert(aColors.join(","));//outputs "red,green,blue"

        alert(aColors.join("-spring-"));//outputs "red-spring-green-spring-blue"

        alert(aColors.join("]["));//outputs "red][green][blue"

        split:分拆字符串

        復(fù)制代碼 代碼如下:

        var sColors="red,green,blue";

        var aColors=sColors.split(",");//outputs ["red", "green", "blue"]

        var redColors=aColors[0].split("");//outputs ["r", "e", "d"]

        concat && slice

        concat:追加數(shù)組

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue"];

        var aColors2=aColors.concat("yellow","purple");

        alert(aColors);//outputs ["red", "green", "blue"]

        alert(aColors2);//outputs ["red", "green", "blue", "yellow", "purple"]

        slice:返回具有特定項的新數(shù)組

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue","yellow","purple"];

        var aColors2=aColors.slice(1);//outputs ["green","blue","yellow","purple"]

        var aColors3=aColors.slice(1,4);//outputs ["green","blue","yellow"]

        push && pop

        跟棧一樣,Array提供了push和pop方法,push方法用于在Array結(jié)尾添加一個或多個項,pop用于刪除最后一個數(shù)組項,返回它作為函數(shù)值

        復(fù)制代碼 代碼如下:

        var stack=new Array;

        stack.push("red");

        stack.push("green");

        stack.push("blue");

        alert(stack);//outputs ["red","green","blue"]

        var vItem=stack.pop();

        alert(vItem);//outputs ["blue"]

        alert(stack);//otputs ["red","green"]

        shift && unshift

        shift:刪除數(shù)組中第一項,將其作為函數(shù)返回值,unshift:把一個項放在數(shù)組的第一個位置,然后把余下的項向下移動一個位置

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue"];

        var vItem=aColors.shift();

        alert(aColors);//outputs ["green","blue"]

        alert(vItem);//outputs ["red"]

        aColors.unshift("black");

        alert(aColors);//outputs ["black","green","blue"]

        reverse && sort

        reverse:顛倒數(shù)組項的順序,sort:按數(shù)組項的值升序排列(首先要調(diào)用toString()方法,將所有值轉(zhuǎn)換成字符串)

        復(fù)制代碼 代碼如下:

        var aColors=["blue","green","red"];

        aColors.reverse();

        alert(aColors);//outputs ["red","green","blue"]

        aColors.sort();

        alert(aColors);//outputs ["blue","green","red"]

        注意:

        復(fù)制代碼 代碼如下:

        var aColors=[3,32,2,5];

        aColors.sort();

        alert(aColors);//outputs [2,3,32,5]

        這是因為數(shù)字被轉(zhuǎn)換成字符串,然后按字符代碼進行比較的。

        splice

        splice:把數(shù)據(jù)項插入數(shù)組的中部

        1、用作刪除:只要聲明兩個參數(shù),第一個參數(shù)為要刪除的第一個項的位置,第二個參數(shù)為刪除項的個數(shù)

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue","yellow"];

        aColors.splice(0,2);

        alert(aColors);//outputs ["blue", "yellow"]

        2、用作插入:聲明三個或以上參數(shù)(第二個參數(shù)為0)就可以把數(shù)據(jù)插入指定位置,第一個參數(shù)為地始位置,第二個參數(shù)為0,第三個及以上參數(shù)為插入項

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue","yellow"];

        aColors.splice(2,0,"black","white");

        alert(aColors);//outputs ["red","green","black","white","blue", "yellow"]

        3、用作刪除并插入:聲明三個或以上參數(shù)(第二個參數(shù)為不0)就可以把數(shù)據(jù)插入指定位置,第一個參數(shù)為地始位置,第二個參數(shù)為要刪除的項的個數(shù),第三個及以上參數(shù)為插入項

        復(fù)制代碼 代碼如下:

        var aColors=["red","green","blue","yellow"];

        aColors.splice(2,1,"black","white");

        alert(aColors);//outputs ["red","green","black","white", "yellow"]

      【JavaScript高級程序設(shè)計:本地對象Array】相關(guān)文章:

      javascript克隆對象深度介紹03-31

      JavaScript中的三種對象04-01

      使用ajax操作JavaScript對象的方法03-08

      網(wǎng)頁程序設(shè)計之實用JavaScript代碼段03-06

      關(guān)于javascript對象之內(nèi)置和對象Math的使用方法03-30

      Javascript中arguments對象的詳解和使用方法03-31

      對javascript的理解03-29

      JavaScript的課堂講解03-31

      主站蜘蛛池模板: 精品熟女亚洲av在线观看| 国产一区二区三区爆白浆| 99久久免费精品色老| 岛国精品一区二区三区| 色噜噜狠狠色综合欧洲| 国产极品视觉盛宴在线观看| 郴州市| 红河县| 于田县| 九龙城区| 国产精品一区二区午夜久久| 日韩成人精品日本亚洲| 91精品日本久久久久久牛牛| 青青草亚洲在线一区观看| 啊v在线视频| 亚洲中文字幕无码不卡电影| 国产一区二区三区最新视频| 国产精品专区一区二区av免费看| 天气| 久久这里只有精品黄色| 突泉县| 亚洲精品国产主播一区二区| 日韩中文字幕无码av| 勃利县| 中国免费一级毛片| 国产精品亚洲A∨无码遮挡| 乌拉特前旗| 色婷婷亚洲十月十月色天| 久久精品国产亚洲av麻豆毛片| 铜梁县| 明光市| 国产品精品久久久久中文| 台安县| 黄色大片一区二区中文字幕| av手机在线天堂网| 国产精品久久成人午夜一区二区 | 国产aⅴ丝袜旗袍无码麻豆| 精选av一区二区三区| 激情五月天俺也去综合网| 极品粉嫩小仙女高潮喷水视频 | 国产乱人视频在线观看播放器 |