I am trying to delete/remove an element from a date array. However, for some reason the last element is not being removed. I will give an example below:
I have a date array like arr[1900-12-20, 1898-12-20, 1900-12-20]; Please consider the elements in the array are dates and not strings.
Here is my code - My code take in an array of dates(input1[0]), one date attribute like '2014-09-30' (input1[1]), and returns an array of dates(output1)
var DobArr = input1[0];
var passedInDt = input1[1];
var prt_year = 0;
var ageInYears = 0;
//Get year for valuation date
valYear = passedInDt.getFullYear();
for (i=0; i<DobArr.length; i++){
prt_year = DobArr[i].getFullYear();
ageInYears = valYear - prt_year;
if (ageInYears >= 110){
removeByIndex(DobArr, i);
}
}
output1 = DobArr;
function removeByIndex(arr, index) {
arr.splice(index, 1);
}
So what the code does is checks if ageInYears >= 110, if it is then I would like to remove the element from array.
Let me give a side note here, an Oracle product will call this script, and input1[0] is an array of date elements. input1[0] in Oracle product looks like input1[0] = {1900-12-20}{1898-12-20}{1900-12-20}
After running my code, DobArr should be empty, instead it has a value of {1898-12-20} ... Why ?? All elements pass ageInYears >= 110, why do i have an element left ? i am confused. splice function should remove the elements completely from the array. Please Help and thanks in advance.
Thanks,