-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArrayObj.html
54 lines (50 loc) · 1.38 KB
/
ArrayObj.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<title>Array Object</title>
</head>
<body>
<h1>Javascript Practical</h1>
<script>
var array = [];
var x = prompt("Enter the size of array");
//Input the elements in the array
for (i = 0; i < x; i++) {
array[i] = prompt("Enter the array Element " + (i + 1));
}
//Display the array elements
for (i = 0; i < x; i++) {
document.write(
"The element are at position " +
i +
" is : " +
array[i] +
"</br> </br>"
);
}
// program to append an object to an array
function insertObject(arr, obj) {
// append object
arr.push(obj);
console.log(arr);
document.writeln(arr + "</br></br>");
}
let object = { x: 12, y: 8 };
insertObject(array, object);
// program to check if an object is an array
function checkObject(arr) {
// check if arr is array
const result = Array.isArray(arr);
if (result) {
console.log(`[${arr}] is an array.`);
document.write("This is an array. </br></br>");
} else {
console.log(`${arr} is not an array.`);
document.write("This is not an array. </br></br>");
}
}
checkObject(array);
console.log(array);
</script>
</body>
</html>