Advertisement
KodingKid

Method 1, 2, and 3 Javascript Arrays

Apr 12th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var cars = [
  2.     "Alfa Romeo",
  3.     "BMW",
  4.     "Chevrolet",
  5.     "Dacia"
  6. ];
  7. document.getElementById("demo").innerHTML = cars[0];
  8. document.getElementById("demo").innerHTML = cars[1];
  9. document.getElementById("demo").innerHTML = cars[2];
  10. document.getElementById("demo").innerHTML = cars[3];
  11. //Method 1
  12. var cars = ["Alfa Romeo", "BMW", "Chevrolet", "Dacia"];
  13. document.getElementById("demo").innerHTML = cars[0];
  14. document.getElementById("demo").innerHTML = cars[1];
  15. document.getElementById("demo").innerHTML = cars[2];
  16. document.getElementById("demo").innerHTML = cars[3];
  17. //Method 2
  18. var car1 = "Alfa Romeo";
  19. var car2 = "BMW";
  20. var car3 = "Chevrolet";
  21. var car4 = "Dacia";
  22. <script>
  23. document.write(car1);
  24. document.write(car2);
  25. document.write(car3);
  26. document.write(car4);
  27. </script>
  28. //this is to be written in a linked html script
  29. //Method 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement