Loop through an array and add every object to ul as an li - Javascript jQuery

Javascript examples for jQuery:Array

Description

Loop through an array and add every object to ul as an li

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head></head>
   <body> 
      <div id="pokeList"> 
         <ul> 
         </ul> 
      </div> 
      <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> 
      <script>
    $(function () {//from w  w  w  .  j av a  2s .co m
        let pokemonList = ['a', 'b', 'c', 'd'];
        for (let i = 0; i < pokemonList.length; i++) {
            $("#pokeList ul").append(`<li>${pokemonList[i]}</li>`);
        }
    });

      </script>  
   </body>
</html>

Related Tutorials