I think it's too late at night for me to figure this out. Basically, I have a master array. I loop over it and remove an element if I find it. I do this for 4 elements.
In the end I want to display any leftover elements. The problem is that I'm not refreshing my array correctly after I remove an element.
Here's the code I'm using which I feel is too much brute force and not enough elegance.
var masks = ["valueOne","valueTwo","valueThree","valueFour","valueFive"];
$.each(masks,function(key,value){
if("valueOne" === value){
// do something
masks.splice($.inArray(value, masks),1);
}else if("valueTwo" === value){
// do something
masks.splice($.inArray(value, masks),1);
}else if("valueThree" === value){
masks.splice($.inArray(value, masks),1);
}else if("valueFour" === value){
// do something
masks.splice($.inArray(value, masks),1);
}
});
console.log( masks.toString() );
I'd expect the console to log "valueFive" but it doesn't. It logs this:
valueTwo,valueFour,valueFive
What's the correct way to refresh an array after updating it? Thanks for any helpful tips.