-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_display.html
31 lines (23 loc) · 1012 Bytes
/
array_display.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<!-- A paragraph where the array elements will be displayed -->
<p id="demo"></p>
<script>
// Declare an array of car brands
const cars = ["Saab", "Volvo", "BMW"];
// Display all the elements of the array as a string
// This will output: Saab,Volvo,BMW
document.getElementById("demo").innerHTML = cars.toString();
// To access and display a single element from the array, uncomment the line below
// This will output: Volvo
// document.getElementById("demo").innerHTML = cars[1];
// To display the elements of the array as a list, uncomment the lines below
// This will create an unordered list: <ul><li>Saab</li><li>Volvo</li><li>BMW</li></ul>
// const listItems = cars.map(car => `<li>${car}</li>`).join('');
// document.getElementById("demo").innerHTML = `<ul>${listItems}</ul>`;
// Note: Only one of the above document.getElementById("demo").innerHTML lines should be active at a time.
</script>
</body>
</html>