[SOLVED] Best way to destroy all children of an entity?

I am using this method:

let child;
for (let i = 0; this.container.children.length > 0; i++) {
    child = this.container.children.pop();
    child.destroy();
}

Is it possible to do so?
Will there be an eternal cycle?

I would probably use a while loop instead:

while(this.container.children.length > 0) {
    this.container.children[this.container.children.length-1].destroy();
}
1 Like