Kevin Powell - CommunityKP-C
Kevin Powell - Community4y ago
4 replies
Jon

Changing value of first loop in a for loop

I'm looping through an array of images and adding them to a carousel. The first image in the carousel needs to have an "active" class, but the rest needs to be without it. Currently my code looks like this
  for (let i = 0; i < json.media.length; i++) {
    mediaArray += `
      <div class="carousel-item active">
      <img src="${json.media[i]}" class="d-block w-100" alt="...">
      </div>
      `


  }


How do i make the first loop have active and the rest not?
Was this page helpful?