-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_array.html
More file actions
55 lines (40 loc) · 1017 Bytes
/
17_array.html
File metadata and controls
55 lines (40 loc) · 1017 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<p>JavaScript array elements are accessed using numeric indexes (starting from 0).</p>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars[1];
</script>
<p>Array.forEach() calls a function for each array element.</p>
<p id="demo1"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let text = "<ul>";
fruits.forEach(myFunction);
text += "</ul>";
document.getElementById("demo1").innerHTML = text;
function myFunction(value) {
text += "<li>" + value + "</li>";
}
</script>
<h2>JavaScript Array Sort</h2>
<p>The lowest number is <span id="demo2"></span>.</p>
<script>
const points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo2").innerHTML = myArrayMin(points);
function myArrayMin(arr) {
let len = arr.length;
let min = Infinity;
while (len--) {
if (arr[len] < min) {
min = arr[len];
}
}
return min;
}
</script>
</body>
</html>