I've been grappling with this issue for hours now, and it seemed so straightforward at first;
My goal with JavaScript is to iterate through an array, retrieve the current index value, and then remove that value from the array. I've read that splice() should be able to achieve this, but no matter what I try, I can't completely empty the array - there always seems to be one value left.
var filtered = array("up", "down", "left");
function resetTags(){
var length = filtered.length;
for(i=0; i <= length; i++){
filtered.splice(i,1);
}
}
EDIT::
Let me provide some additional context:
Essentially, my aim is to monitor a list of selected class values that are captured when an item is clicked: var filtered = array();
jQuery("li a").click(function () {
tag = jQuery(this).text();
addFiltered(tag);
});
function addFiltered(param){
var inArray = jQuery.inArray(param,filtered);
if(inArray > -1){
//param is in the array, so we need to remove it
filtered.splice(index, 1);
});
}else{
//param isn't in the array, so we want to add it
filtered.splice(0, 0, param);
});
}
}