I have the following function on clicking a button. Now even though I clear the array when the button is clicked for the second time, the array value is still there, so I can see two values in the console log. I am doing this in Angular and am not sure how to fix this issue. Any help will be appreciated.
updateLeaveApplication(event) {
let leaveID = [];
leaveID.length = 0;
console.log(leaveID);
if (_.isArray(event.leave_id)) {
_.forEach(event.leave_id, function (value) {
leaveID.push(value.leave_id);
});
} else {
leaveID.push(event.leave_id);
}
}