I have a function to dynamically create a card, which takes in an array y.
createCards = (y) => {
const matchElement = document.createElement('div');
matchElement.classList.add('match-title');
const matchInnerHTML = `
<div class="info>
<span class="number">${y[0]}</span>
</div>
`
;
}
The above code works as expected. However, I want the div elements to be created dynamically as the value of i changes.
I tried to use a for loop the following way to update value of i
createCards = (y) => {
const matchElement = document.createElement('div');
matchElement.classList.add('match-title');
for(let i=0; i<=y.length; i++){
const matchInnerHTML = `
<div class="info>
<span class="number">${y[i]}</span>
</div>
`
;
matchElement.innerHTML = matchInnerHTML;
match_container.appendChild(matchElement);
}
}
I'm getting undefined on my browser window. I want the cards to be generated dynamically as array gets updated. How to get around this?