title: Is their a way to make the for loop go through every item in the array?
body: <p>I'm trying to make a 2D platformer game but the collision code with the objects in the world isn't working as intended. I'm using the collide2D library to help with collision.</p>
  <p>The issue is that the collision code is being executed but only for the last item in the &quot;objs&quot; array. When I load the game the character ignores all the blocks/items and only collides with the last object in the array. objCount is just a global variable that lets me change it when I add more objects.</p>
  <p>I know I can write the code out for every item in the array but I was hoping to condense it into a loop.</p>
  <pre><code>objCount = 20 //the number of items in the array
      
  for (let i = 0; i &lt; objCount; i++){
      if (collideRectRect(player1.x, player1.y, player1.w, player1.h, objs[i].x, objs[i].y, objs[i].s, objs[i].s)){
          minPh = objs[i].y-player1.h;
      }
      else{
          minPh = minH-player1.h;
      }
  }
  </code></pre>