• Question
  • Anyone know how to make this faster?

so basically i have
var effects = [];
function effect(){
// all other properties removed for simplicity of this post
this.index = effects.length;
effects.push(this);
}

and to get rid of the effect i have this:
effect.prototype.terminate = function(){
for(var i = this.index+1; i < effects.length; i++){
effects[i].index--;
}
effects.splice(this.index,1);
};

this feels kinda sloppy and error prone, yet i can't think of a better way to terminate the effects. anyone know of a faster and/or more reliable way to do this(mostly need faster)?

dog what are you even tryna do here? if you want us to try and help you to get it faster then at least try to explain what ur trying to accomplish

also if it aint broke then dont try to fix it

    Letti42
    tryna find a way to splice effect objects out of an array in a faster way than having to loop through everything else and change the indexes of those other objects

      ackvonhuelio hmm well i was trying to do something a little while back where using a for in loop where all you have to do is set the current index to undefined or deleting it idrk that way it should be excluded from the array though i am a bit unaware of how much faster it is compared to just splicing them out of the list

      var list = ["obj1", "obj2", "obj3", undefined, "obj4"];
      for(var i in list) {
      console.log(list[i])
      }
      delete list[0]
      for(var i in list) {
      console.log(list[i])
      }

      though i'm sure if it would be "faster", though if your going off of an id based system it may be best to just allocate the ids seperately and run the system off that and clean your main particle tree when the system isn't stressing out that way it doesn't spike the only thing you'll lose that way is a bit of memory but it can be mitigated slightly by setting it to null for the GC to pick up on it which may be better than the delete method.... if you need a more in depth thingy dm me on discord so i don't forget

        Chat