-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayExamples.html
More file actions
77 lines (69 loc) · 1.88 KB
/
ArrayExamples.html
File metadata and controls
77 lines (69 loc) · 1.88 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Array Methods </title>
</head>
<script>
"use strict";
function modify() {
let i = Number(ie.value); let x = xe.value;
xe.value = a[i]; a[i] = x; reportA("a["+i+"] = "+x);
}
function remove() {
let i = Number(ie.value);
xe.value = a[i]; a.splice(i, 1); reportA("remove "+i);
}
function push() {
let x = xe.value; let i = Number(ie.value);
a.push(x); reportA("push "+x);
}
function popA() {
xe.value = a.pop(); reportA("pop ");
}
function reportA(str) {
outA.innerText = "a = [ "+ a.join(", ")+" ] "+a.length;
console.log(str);
}
function find(){
let x = xe.value;
var fIndex = a.indexOf(x);
ie.value=fIndex;
}
function reverse(){
outA.innerText = "a = [ "+ a.reverse() + " ] " + a.length;
}
function fill(){
let x = xe.value;
outA.innerText = "a = [ "+ a.fill(x) + " ] " + a.length;
}
</script>
<body>
<h2 id=title></h2>
<p id=outA></p>
<p>
i = <input type=number id=ie value=1 style="width:40px">  
x = <input type=text id=xe value=53 style="width:99px">
</p><p>
<input type=button value="a[i]=x" onClick="modify()">
<input type=button value="remove" onClick="remove()">
<input type=button value="push x" onClick="push()">
<input type=button value="x=pop" onClick="popA()">
<input type=button value="Reverse" onclick="reverse()">
<input type=button value="Find" onclick="find()">
<input type=button value="Fill" onclick="fill()">
</p>
<hr />
<p>Ref:
<a href="https://www.w3schools.com/js/js_arrays.asp" target="ExternalDocument">Array Examples</a></p>
<p>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Keyed_collections" target="ExternalDocument">Set Examples</a>
</p>
<script>
title.innerText = document.title;
const a = [234, "abc", "son"]; //initially
reportA("start");
</script>
</body>
</html>