I am looking to incorporate my javascript array into a bootstrap carousel so that the carousel can display all the elements from the array and determine which picture should be shown based on the data. I also want it to display the title, subtitle, and alt text of each picture on the carousel items. However, I am unsure of how to connect the two, any suggestions? Here is an example of the array I am working with:
const data = [
{
src: 'italian.jpg',
title: 'Italian cuisine',
subtitle: 'Great italian cuisine',
alt: 'Image of italian cuisine'
},
{
src: 'mexican.jpg',
title: 'Mexican cuisine',
subtitle: 'Amazing mexican cuisine',
alt: 'Image of mexican cuisine'
},
{
src: 'japanese.jpg',
title: 'Japanese cuisine',
subtitle: 'Traditional japanese cuisine',
alt: 'Image of japanese cuisine'
}
];
document.getElementById("carousel-item").innerHTML = data;
The carousel I am using is a basic bootstrap carousel.
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-item">
<img src="..." alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<div class="carousel-item">
<img src="..." alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<div class="carousel-item">
<img src="..." alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>