Advertisement
RokiAdhytama

Init Array 2 - Chapter 11

Jul 3rd, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <html xmlns = "http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>Initializing an Array with a Declaration</title>
  4.  
  5. <script type = "text/javascript">
  6. <!--
  7. function start()
  8. {
  9. // Initializer list specifies number of elements and
  10. // value for each element.
  11. var colors = new Array( "cyan", "magenta",
  12. "yellow", "black" );
  13. var integers1 = [ 2, 4, 6, 8 ];
  14. var integers2 = [ 2, , , 8 ];
  15.  
  16. outputArray( "Array colors contains", colors );
  17. outputArray( "Array integers1 contains", integers1 );
  18. outputArray( "Array integers2 contains", integers2 );
  19. }
  20.  
  21. // output "header" followed by a two-column table
  22. // containing subscripts and elements of "theArray"
  23. function outputArray( header, theArray )
  24. {
  25. document.writeln( "<h2>" + header + "</h2>" );
  26. document.writeln( "<table border = \"1\"" +
  27. "width = \"100%\">" );
  28. document.writeln( "<thead><th width = \"100\" " +
  29. "align = \"left\">Subscript</th>" +
  30. "<th align = \"left\">Value</th></thead><tbody>" );
  31.  
  32. for ( var i = 0; i < theArray.length; i++ )
  33. document.writeln( "<tr><td>" + i + "</td><td>" +
  34. theArray[ i ] + "</td></tr>" );
  35.  
  36. document.writeln( "</tbody></table>" );
  37. }
  38. // -->
  39. </script>
  40.  
  41. </head><body onload = "start()"></body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement