欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          es6數(shù)組怎么去掉規(guī)定的值

          去掉方法:1、用“arr.splice(arr.indexOf("指定值"),1)”語句,用indexOf()查找指定值的位置,再用splice()根據(jù)位置刪除該元素;2、用“delete arr[arr.indexOf("值")]”語句。

          es6數(shù)組怎么去掉規(guī)定的值

          本教程操作環(huán)境:windows7系統(tǒng)、ECMAScript 6版、Dell G3電腦。

          es6數(shù)組去掉規(guī)定的值

          方法1:利用indexOf()和splice()方法

          實現(xiàn)思路:

          • 利用indexOf()查找指定值的位置

          • 使用splice()根據(jù)位置刪除該元素

          實現(xiàn)代碼:

          var arr = ["Banana", "Orange", "Apple", "Mango"]; console.log(arr); var a = arr.indexOf("Apple"); arr.splice(a,1); console.log(arr);

          es6數(shù)組怎么去掉規(guī)定的值

          方法2:利用indexOf()方法和delete關(guān)鍵字

          實現(xiàn)思路:

          • 利用indexOf()查找指定值的位置

          • 使用delete關(guān)鍵字根據(jù)位置刪除該元素

          delete arr[index];

          實現(xiàn)代碼:

          var arr = ["Banana", "Orange", "Apple", "Mango"]; console.log(arr); var index = arr.indexOf("Orange"); delete arr[index]; console.log(arr);

          es6數(shù)組怎么去掉規(guī)定的值

          說明:使用delete刪除元素后,該下標(biāo)位置元素會顯示為undefined,即空位元素

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號