# How to detect collisions of objects in two different arrays?(html canvas)

I am making a canvas game where you shoot at an endless amount of enemies. My problem is that the I am not sure how to make the objects from the bullets array collide with those of the enemy array. Here is what I have:

enemies.forEach(hitCheck)


Then:

var hitCheck = function(object){
var a = bullets.length

if (bullets[a].x < object.x + object.width  && bullets[a].x + bullets[a].width  > object.x &&
bullets[a].y < object.y + object.height && bullets[a].y + bullets[a].height > object.y) {object.x += 400}
}


I think the problem here is that you're not iterating over the bullets array.

Instead of just setting a to bullets.length, use a for loop inside hitCheck:

for (var a = 0; a < bullets.length; a++) {
if (bullets[a].x < object.x + object.width
&& bullets[a].x + bullets[a].width  > object.x
&& bullets[a].y < object.y + object.height
&& bullets[a].y + bullets[a].height > object.y) {
object.x += 400
}
}