Faced such a problem: you need to insert li tags in the <ul> tag in an amount equal to the number of elements in the array.

 var player = ["10","9"]; //это как пример while (i <= player.length){ cardsPlayer.innerHTML += '<li data-value=' + '"' + player[i] + playerSymbol[i] + '"' + '><p><span></span>'+ playerSymbol[i] + '</p></li>'; i++; } 

But instead of 2 elements, 3.2 is displayed normally, and the third Undefined .
Where did I make a mistake? yet true, the array is strictly specified.

    1 answer 1

    Error in the erroneous use of <= instead of < because array indexing starts from 0.

    In this case, it is better to use the functions for working with arrays. This is where the map function will work.

     cardsPlayer.innerHTML += player.map((p,i)=>`<li data-value="${p}${playerSymbol[i]}"><p><span></span>${playerSymbol[i]}</p></li>`).join();