How how do I delete a jQuery Deferred from an array when it finishes? I have:
myarray[key]=$.ajax({
}).done(function(response){
// work with response,
// then delete myarray[key];
});
This does not work:
var myvar=function(){
if(myvar){
alert(1);
}
}
Seems like the declaration has to finish for an event of checking whether the variable is set or not, so delete of the variable inside the variable declaration shouldn’t work How to, with a timeout?
This depends on whether or not myarray is an Array or an Object. If it’s an Object, you could just do
But if it’s an Array, then it’s a little more complicated. John Resig wrote post about Array element removal here
If you want to do it more simply, and it’s an Array, you could remove it with
But you should note that
myarraydoesn’t get any smaller when you do this.$.ajaxreturns a Deferred object, and.done()returns a different Deferred object. Optimally, you’d do the following: