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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] >[success] # 擴展運算符 ~~~ '不定參數'和'擴展運算符'很相似,前者是把'參數合并成一個數組',后者是把'數組打散成各自獨立' ~~~ 如下我有想通過`Math`的`max`方法過濾出參數最大的那個值 ~~~ let value1 = 25, value2 = 50 console.log(Math.max(value1, value2)) // 50 ~~~ 現在有一個需求,想通過一個數組,過濾出數組中最大的那個值,但是`max`方法的參數不支持傳入數組,該怎么辦 >[success] ## ES5將數組打散 ~~~ 'ES5'通過使用'apply'方法來將'數組打散','apply'方法第一個參數為調用的那個方法的'this', 'apply'方法的第二個參數為'數組',例子如下: ~~~ ~~~ let arr = [25, 50, 75, 100] console.log(Math.max.apply(Math, arr)) // 100 ~~~ <br/> >[success] ## ES6將數組打散 1. 擴展運算符基礎功能 ~~~ let arr = [25, 50, 75, 100] console.log(Math.max(...arr)) // 100 ~~~ ~~~ 如果數組是'負數'的情況下,可以為'max'方法設置一個'最小值0'(防止負數偷偷返回) ~~~ ~~~ let arr = [-25, -50, -75, -100] console.log(Math.max(...arr, 0)) // 0 ~~~ 2. 淺拷貝數組 ~~~ 2.1 '傳統方式': // 數組1 let arr = [1, 2, 3, 4, 5, 6] // 數組2 let arr2 = []; // 淺拷貝數組 arr.forEach(i => arr2.push(i)) // 修改數組1 arr[0] = 222 console.log(arr, 'arr') // [ 222, 2, 3, 4, 5, 6 ] console.log(arr2, 'arr2') // [ 1, 2, 3, 4, 5, 6 ] 2.2 'ES6擴展運算符方式': // 數組1 let arr = [1, 2, 3, 4, 5, 6] // 數組2 let arr2 = [...arr]; // 修改數組1 arr[0] = 222 console.log(arr, 'arr') // [ 222, 2, 3, 4, 5, 6 ] console.log(arr2, 'arr2') // [ 1, 2, 3, 4, 5, 6 ] ~~~ 3. 淺拷貝對象 ~~~ 3.1 '傳統方式': // 對象1 let obj = { a: '小明', b: false } // 對象2 let obj2 = {} // 淺拷貝 for (key in obj) { obj2[key] = obj[key] } // 修改對象1 obj['b'] = true console.log(obj) console.log(obj2) 3.2 'ES6擴展運算符方式': // 對象1 let obj = { a: '小明', b: false } // 對象2 let obj2 = { ...obj } // 修改對象1 obj['b'] = true console.log(obj) console.log(obj2) ~~~
                  <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>

                              哎呀哎呀视频在线观看