今天寫js的時候碰到一坑,記錄下。
通過正則篩選出數組中哪些元素需要刪除,之後使用倒敘刪除法。
filterTreeData = function (list){ var rep = new RegExp("^[1-2]"); for (var i = list.length-1; i > -1 ; i-- ){ var one = list[i]; if(rep.test(parseInt(one.chr_code))){ list.splice(i,1); } } return list; }