<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [toc] #### 1.手寫 forEach forEach((item, index, arr)),無返回值 ```js Array.prototype.mForEach = function (calback) { for (let i = 0; i < this.length; i++) { calback(this[i], i, this); } }; ``` #### 2.手寫 map map((item, index, arr)),返回新數組 ```js Array.prototype.mMap = function (callback) { let res = []; for (let i = 0; i < this.length; i++) { res.push(callback(this[i], i, this)); // 每次都往 res push callback的返回值 } return res; }; ``` #### 3.手寫filter filter 返回所有滿足條件的值 ```js // filter Array.prototype.mFilter = function (callback) { let res = []; for (let i = 0; i < this.length; i++) { callback(this[i], i, this) && res.push(this[i]); } return res; }; ``` #### 4.手寫every 全部滿足則返回true,有一項不滿足則return false,中斷遍歷 ```js Array.prototype.mEvery = function (callback) { for (let i = 0; i < this.length; i++) { if (!callback(this[i], i, this)) { return false; } } return true; }; ``` #### 5.手寫some 只要有一個為 true ,則返回 true,中斷 ```js Array.prototype.mSome = function (callback) { for (let i = 0; i < this.length; i++) { if (callback(this[i], i, this)) return true; } return false; }; ``` #### 6.手寫 find 找到第一位 ```js Array.prototype.mFind = function (callback) { for (let i=0; i<this.length; i++) { if(callback(this[i], i, this)) return this[i] } } ``` #### 7.手寫 findIndex 找到第一位的index ```js Array.prototype.mFindIndex = function (callback) { for (let i=0; i<this.length; i++) { if(callback(this[i], i, this)) return i } } ``` #### 8.手寫reduce cur 從第一項開始 每次將 callback 中的返回值作為下一次的 pre 如果傳了第二個參數,則 pre 從傳的參開始, cur 從第0項開始 如果沒傳第二個參數,則 pre 從第0項開始,cur 從第0項開始 返回最終的 pre ```js Array.prototype.mReduce = function (callback, ...args) { let start = 0 prev = null if (args.length === 0) { prev = this[0] start = 1 } else { pre = args[0] } for (let i=start; i<this.length; i++) { prev = callback(prev, this[i], i, this) } return prev } ``` #### 9.手寫fill fill(value, start, end) 會修改原數組,也會返回新數組 如果end為負數,則表示倒數第幾位 ```js Array.prototype.mFill = function (initValue, start=0, end=this.length) { // 從倒數開始 if (end < 0) { end = this.length + end } for (let i=start; i<end; i++) { this[i] = initValue } return this } ``` #### 10.join ```js Array.prototype.mJoin = function(s = ',') { let str = '' for(let i=0; i<this.length; i++) { if (i === this.length - 1) { str = str + this[i] } else { str = str + this[i] + s } } return str } ``` #### 11.拍平 flat ```js let arr = [1, 2, [3, 4], [5, 6, [7, 8]]]; Array.prototype.mFlat = function (num = Infinity) { let arr = this let i = 0 // 展開層級 while(arr.some(item => Array.isArray(item))) { arr = [].concat(...arr) i++ if (i>=num) { break } } return arr } ```
                  <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>

                              哎呀哎呀视频在线观看