I've been attempting to remove an item from an array, but for some reason, it's not working. Here's the code I'm using:
vm.Continue = function () {
$scope.invalidList = [];
if (vm.errorexsist === true) {
var table = document.getElementById('errortabel');
for (var r = 0, n = table.rows.length; r < n; r++) {
if (r > 0) {
$scope.invalidList.push({
Error: table.rows[r].cells[0].val,
FirstName: table.rows[r].cells[1].children[0].value,
Email: table.rows[r].cells[2].children[0].value,
PhoneNumber: table.rows[r].cells[3].children[0].value,
Location: table.rows[r].cells[4].children[0].value,
Department: table.rows[r].cells[5].children[0].value
});
}
}
var i = $scope.invalidList.length;
while (i--) {
if (IsEmailValid($scope.invalidList[i].Email) === true && IsPhoneNumValid($scope.invalidList[i].PhoneNumber) === true) {
$scope.invalidList.splice(i, 1);
}
}
}
};
The issue with the above code is that it always removes the item at index zero, even when the condition in the if statement is not met.