Why below array is not being removed.
var removeableIndex =-1;
bookingStatus.bookings.filter(function(item, index) {
if(item.id == id){
removeableIndex = index;
return true;
}
return false;
});
console.log(removeableIndex)
if(removeableIndex)
var result = bookingStatus.bookings.splice(removeableIndex,1);
I have passed the correct array of bookings. Filter is correctly matching. This does not remove item when removeableIndex is 0. Suppose if removeableIndex is grater than zero it is being removed.
Below code with small change works correctly for all cases including removeableIndex is 0.
var removeableIndex =-1;
bookingStatus.bookings.filter(function(item, index) {
if(item.id == id){
removeableIndex = index;
return true;
}
return false;
});
console.log(removeableIndex)
if(removeableIndex > -1)
var result = bookingStatus.bookings.splice(removeableIndex,1);
Only difference is that if(removeableIndex > -1)
I would like to know why didnt the first set of code did not remove the item only when it is at zero index.