从数组中删除不起作用

时间:2014-11-28 15:19:12

标签: javascript html angularjs

所以,我试图从数组中删除它的元素值不等于我指定的值:

代码:http://pastebin.com/hUc3mVLv

$scope.enablePVR = function()
{
        for (i = 0; i < $scope.new_epg.length; i++) {
                start_time = convert_time($scope.new_epg[i].start);
                $scope.new_epg[i].title = $scope.new_epg[i].title.replace(/<(?:.|\n)*?>/gm, '');
                $scope.new_epg[i].description = "";
                $scope.new_epg[i].time = start_time;
        }
        archiveEPG = [];
        for(var i=0; i<archiveEPG.length; i++) {
                var e = document.getElementById("dateSelect");
                if($scope.new_epg[i].start.split(" ")[0] == e[e.selectedIndex].value) {
                        archiveEPG[archiveEPG.length+1] = $scope.new_epg[i];
                }
        }
        document.getElementById("dateSelect").remove(0);
        $scope.get_epg(null, true, archiveEPG);
}

1 个答案:

答案 0 :(得分:-1)

.remove(0)无效,您可以添加此功能以使其有效:

Array.prototype.remove = function(index) {
    return this.splice(index, 1); // The second parameter is the number of elements to remove.
}