<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [toc] #### 1.增刪:改變原數組操作 ``` push: 返回新數組長度 unshift: 添加至開頭,返回新數組長度 pop: 刪除最后一位,返回刪除的元素 shift: 刪除第一位,返回刪除的元素 ``` #### 2.修改:改變原數組 splice(inde, count, value, value),返回被刪除的部分組成的數組 ```js let arr = [1, 2, 3] // index 為0則為新增 arr.splice(1, 0, 4, 5, 6) // [1, 4, 5, 6, 2, 3] let res = arr.splice(1, 1) console.log(arr, res); // [1, 3] , [2] ``` #### 3.獲取子數組,不改變原數組 slice(start, end),左閉又開 ```js let arr = [1, 2, 3, 4, 5] console.log(arr.slice(1, 3)); // [2,3] console.log(a.slice(1)) // [2, 3, 4, 5] 只有一個參數且不小于0時,則從此索引開始截取到數組的末尾 console.log(a.slice(1, -1)) // [2, 3, 4] 從第1位截取到倒數第1位 ``` 數組沒有substr和substring方法,該方法屬于字符串操作 #### 3.查找 indexOf: 返回找到的下標,-1為未找到 lastIndexOf: 從最后開始查找,index值依然從左邊開始計算 includes: 返回 true false ```js let arr = [1, 2] arr.includes(2)) // true ``` #### 4.sort排序 + a-b 從小到大排序 ```js a = [31, 22, 27, 1, 9] a.sort((a, b) => { return a - b }) console.log(a) // [1, 9, 22, 27, 31] 按數值大小正序排列 ``` + b-a 從大到小排序 #### 5.拼接數組 concat,返回新數組,不會改變原數組 ```js let arr = [1, 2, 3] let arr2 = [4, 5] console.log(arr.concat(arr2)); // [1, 2, 3, 4, 5] ``` #### 6.數組遍歷 ``` forEach((item, index, arr)) map((item, index, arr)):返回新數組 filter((item, index, arr)): 返回符合過濾條件的新數組 ``` every:判斷是否每一項都滿足條件,只有全部滿足才會返回 true,有一項不滿足則中斷返回false some: 只要有一項滿足就會返回 true,some可以中斷 ```js var arr = [1, 2, 3, 4, 5] var res= arr.every(function (item, index, a) { return item < 10 }) console.log(res) // true ``` reduce: ```js let res = arr.reduce((pre, current, index, arr) => { return pre + current }, 0) console.log(res); // 6 ``` findIndex:查找滿足條件的第一項的index值 ```js let arr = [1, 2, 3, 4, 5] let idx = arr.findIndex(item => { return item > 2 }) console.log(idx); // 2 ``` find: 查找滿足條件的第一項 item ```js let item = arr.find(item => { return item > 2 }) console.log(item); // 3 ``` #### 7.fill 方法 fill(value, start, end) 左閉右開 1.fill修改會修改原數組 ```js let arr2 = [1, 2, 3, 4]; arr2.fill(1, 2); // [1, 2, 1, 1] ``` 2.fill創建一個50個內容全為1的數組 ```js const arr3 = new Array(50).fill(1); console.log(arr3); ``` #### 8. flat 數組拍平 不改變原數組 ```js let arr = [1, 2, [3, 4, [5, 6, 7]]]; console.log(arr.flat()); // 默認拍平一層,不改變原數組 [1, 2, '', 3, 4, Array(3)] console.log(arr.flat(Infinity)); // 拍平所有 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看