screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>JavaScript Array Length</title> </head> <body> <h1>Get Size of Array Javascript</h1> <!-- HTML elements for displaying array and button --> <p id="array"></p> <p id="arrayOutput"></p> <button onclick="checkArrayLength()">Check Array Length</button> <script> // JavaScript code let myArray = [1, 2, 3, 4, 5]; // Initial display of the array document.getElementById("array").innerHTML = "<strong>Array:</strong> " + myArray.join(", "); // Function to display the length of the array function checkArrayLength() { let arrayOutputElement = document.getElementById("arrayOutput"); // Display the length of the array arrayOutputElement.innerHTML = "<strong>Array Length:</strong> " + myArray.length; } </script> </body> </html>