1. 程式人生 > >[javascript] 如何 一次刪除多個數組元素

[javascript] 如何 一次刪除多個數組元素

一次性刪除陣列中的多個元素,使用逆向迴圈,否則會破壞掉元素下標,得不到正確的結果

            var data = {"LTEParaGetRsp":{"RspStatus":"Success","MsgCode":"0","GetApConfList":[
                    {"index":1,"ssid":"222","bssid":"LocalSSID_11:22:33:44:55:22","security_mode":"WPAPSK","channel":"1","signLevel":"31dB"},
                    {"index"
:2,"ssid":"333","11:22:33:44:55:33","security_mode":"WPA2PSK","channel":"1","signLevel":"31dB"}, {"index":3,"ssid":"444","LocalSSID_11:22:33:44:55:44","security_mode":"WPAPSKWPA2PSK","channel":"1","signLevel":"31dB"}]}}; param = data.LTEParaGetRsp.GetApConfList; //del ap list its own ssid...start
console.log(param); for(var i = param.length - 1 ; i >= 0 ; i--) //一次性刪除陣列中的多個元素,使用逆向迴圈,否則會破壞掉元素下標,得不到正確的結果 { var tmp = param[i].bssid; if(tmp.indexOf("LocalSSID_") != -1) // not find return -1 { param.splice
(i,1); } } console.log(param); //del ap list its own ssid...end