How to do Collision Detection when there are many objects (JavaScript)

I’m using this logic to detect intersection of 2 rectangles if (this.position.x < (alien.position.x + alien.width) && (this.position.x + this.width) > alien.position.x && this.position.y < (alien.position.y + alien.height) && (this.position.y + this.height) > alien.position.y) { return true } else { return false } It works, but the thing is, I have to iterate through all…

Details