Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title>HTML Table Array Loop Demo</title>
- </head>
- <body>
- <style>
- table, p {
- font-family: arial, sans-serif;
- border-collapse: collapse;
- width: 100%;
- }
- td, th {
- border: 1px solid #dddddd;
- text-align: left;
- padding: 8px;
- }
- tr:nth-child(even) {
- background-color: #dddddd;
- }
- </style>
- <body>
- <p>PETS</p>
- <table id="myTable">
- </table>
- <br>
- <script>
- function myFunction() {
- var pets = ["Turtle", "Dog", "Cat", "Bird", "Fish"];
- var i = 0;
- while (i < pets.length) {
- var table = document.getElementById("myTable");
- var row = table.insertRow();
- var cell1 = row.insertCell(0);
- var cell2 = row.insertCell(1);
- cell1.innerHTML = pets[i];
- cell2.innerHTML = i+1;
- i++;
- }
- }
- myFunction()
- </script>
- </body>
- </html>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement