• 
    

      <address id="upfr9"><pre id="upfr9"><strike id="upfr9"></strike></pre></address>
      1. <address id="upfr9"><tr id="upfr9"></tr></address><dl id="upfr9"></dl>

        js數(shù)組的常用方法有哪些

        這篇文章主要介紹了js數(shù)組的常用方法有哪些的相關(guān)知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇js數(shù)組的常用方法有哪些文章都會有所收獲,下面我們一起來看看吧。

        成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比石屏網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式石屏網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋石屏地區(qū)。費用合理售后完善,十年實體公司更值得信賴。

        數(shù)組的常用方法有下面幾種

        方法 釋義

        push()

        push()?法可以接收任意數(shù)量的參數(shù),并將它們添加到數(shù)組末尾,返回數(shù)組的最新?度

        unshift()

        unshift() 在數(shù)組開頭添加任意多個值,然后返回新的數(shù)組?度

        splice()

        傳?三個參數(shù),分別是開始位置、 0 (要刪除的元素數(shù)量)、插?的元素,返回空數(shù)組

        concat()

        ?先會創(chuàng)建?個當(dāng)前數(shù)組的副本,然后再把它的參數(shù)添加到副本末尾,最后返回這個新構(gòu)建的數(shù)組,不會影響原始數(shù)組

        pop()

        pop() ?法?于刪除數(shù)組的最后?項,同時減少數(shù)組的 length 值,返回被刪除的項

        shift()

        shift() ?法?于刪除數(shù)組的第?項,同時減少數(shù)組的 length 值,返回被刪除的項

        splice()

        傳?兩個參數(shù),分別是開始位置,刪除元素的數(shù)量,返回包含刪除元素的數(shù)組

        slice()

        slice() ?于創(chuàng)建?個包含原有數(shù)組中?個或多個元素的新數(shù)組,不會影響原始數(shù)組

        indexOf()

        返回要查找的元素在數(shù)組中的位置,如果沒找到則返回 -1

        includes()

        返回要查找的元素在數(shù)組中的位置,找到返回 true ,否則 false

        find()

        返回第?個匹配的元素

        數(shù)組的兩個排序方法

        reverse()    反轉(zhuǎn)數(shù)組

        let values = [1, 2, 3, 4, 5];

        values.reverse();

        alert(values); // 5,4,3,2,1

        sort()

        sort() ?法接受?個?較函數(shù),?于判斷哪個值應(yīng)該排在前?

        數(shù)組方法的基本操作   

        數(shù)組基本操作可以歸納為 增、刪、改、查,需要留意的是哪些?法會對原數(shù)組產(chǎn)?影響,哪些?法不會

        push()

        let colors = []; // 創(chuàng)建?個數(shù)組

        let count = colors.push("red", "green"); // 推?兩項

        console.log(count) // 2

        unshift()

        let colors = new Array(); // 創(chuàng)建?個數(shù)組

        let count = colors.unshift("red", "green"); // 從數(shù)組開頭推?兩項

        alert(count); // 2

        splice()

        let colors = ["red", "green", "blue"];

        let removed = colors.splice(1, 0, "yellow", "orange")

        console.log(colors) // red,yellow,orange,green,blue

        console.log(removed) // []

         concat()

        let colors = ["red", "green", "blue"];

        let colors2 = colors.concat("yellow", ["black", "brown"]);

        console.log(colors); // ["red", "green","blue"]

        console.log(colors2); // ["red", "green", "blue", "yellow", "black",

        "brown"]

        pop()

        let colors = ["red", "green"]

        let item = colors.pop(); // 取得最后?項

        console.log(item) // green

        console.log(colors.length) // 1

        shift()

        let colors = ["red", "green"]

        let item = colors.shift(); // 取得第?項

        console.log(item) // red

        console.log(colors.length) // 1

        splice()

        let colors = ["red", "green", "blue"];

        let removed = colors.splice(0,1); // 刪除第?項

        console.log(colors); // green,blue

        console.log(removed); // red,只有?個元素的數(shù)組

        1234

        slice()

        let colors = ["red", "green", "blue", "yellow", "purple"];

        let colors2 = colors.slice(1);

        let colors3 = colors.slice(1, 4);

        console.log(colors) // red,green,blue,yellow,purple

        concole.log(colors2); // green,blue,yellow,purple

        concole.log(colors3); // green,blue,yellow

        splice()

        let colors = ["red", "green", "blue"];

        let removed = colors.splice(1, 1, "red", "purple"); // 插?兩個值,刪除?個元素

        console.log(colors); // red,red,purple,blue

        console.log(removed); // green,只有?個元素的數(shù)組

        indexOf()

        let numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1];

        numbers.indexOf(4) // 3

        includes()

        let numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1];

        numbers.includes(4) // true

        find()

        const people = [

         {

         name: "Matt",

         age: 27

         },

         {

         name: "Nicholas",

         age: 29

         }

        ];

        people.find((element, index, array) => element.age < 28) // // {name:

        "Matt", age: 27}

        關(guān)于“js數(shù)組的常用方法有哪些”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“js數(shù)組的常用方法有哪些”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

        文章名稱:js數(shù)組的常用方法有哪些
        網(wǎng)站地址:http://www.jbt999.com/article10/jeiddo.html

        成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站維護微信公眾號、軟件開發(fā)、搜索引擎優(yōu)化、

        廣告

        聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

        網(wǎng)站建設(shè)網(wǎng)站維護公司

      2. 
        

          <address id="upfr9"><pre id="upfr9"><strike id="upfr9"></strike></pre></address>
          1. <address id="upfr9"><tr id="upfr9"></tr></address><dl id="upfr9"></dl>
            中文字幕精品在线 | 欧美熟女一区二区 | 日韩无码久久 | 国产精品嫩苞又嫩又紧又爽AV | 亚洲免费观看高清在线观看 | 午夜噜噜| 欧美操逼免费视频 | 成人黄色靠逼视频 | 五月丁香六月婷婷久久 | 国产精品秘 麻豆 |