-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut4.html
More file actions
98 lines (76 loc) · 2.78 KB
/
tut4.html
File metadata and controls
98 lines (76 loc) · 2.78 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<html>
<head>
<title>JS tut 4</title>
</head>
<body>
<h3>JS Tut 4</h3>
<script language="javascript" type="text/javascript">
function test1()
{
var statArray = new Array(10); //static declaration
var othrArray = new Array();
othrArray[0]="hue";
othrArray[1]="123"
othrArray[2]=23;
othrArray[3] = new Array();
othrArray[3][0] = 1;
othrArray[3][1] = 2;
arr = ['hue', 'bahue', 'ahue'];
// document.write("->");
document.write(othrArray );
document.write("<br/> >length of arr : " + arr.length);
document.write("<br/><br/>");
// for (i = 0; i < othrArray.length ; i++) {
// document.write(i + " " + othrArray[i]+"<br/>");
// }
}
function generateArray1()
{
//concat 2 arrays
sampArry1 = new Array();
sampArry1[0] = "vw";
sampArry1[1] = "opel";
sampArray2 = ['land rover', 'bentely'];
sampArray3 = sampArry1.concat(sampArray2);
//document.write(sampArray3);
return sampArray3;
}
function printArrFunc(arr)
{
//showcase diverse functionalities of arrays
document.write("Array Str : " + arr.join(" ")+ "<br/ >");
document.write("Array Slice : " + arr.slice(0,2)+ "<br/ >");
document.write("Array Reversed : " + arr.reverse()+ "<br/ >");
}
function arraySplicing()
{
var numList = [2, 8, 6, 0, 16, 11, 9 ];
document.write("Sort array : " + numList.sort() + "<br />");
document.write("Splice array : " + numList.splice(0,3) + "<br />"); // it chops the array, knocks off the elemnts between 0, 3
document.write("Array after splice : " + numList + "<br />" ); // shows the ressult of splicing
document.write("Replace array : " + numList.splice(0,2,22,23) + "<br />"); // knock out the elems between 0,2 and replace em with 22,23
document.write("Array after splice : " + numList + "<br />" );
}
function multiDimArr()
{
var multiDim = [ [1,2,3] , [4,5,6] ];
//document.write(multiDim[1][2] + "<br />");
for(var i= 0 ; multiDim.length; i++)
{
for(var j=0; multiDim[i].length ; j++)
{
document.write(multiDim[i][j] + " ");
}
document.write("<br / >");
}
}
</script>
<p> ------------------ <p>
<script language="javascript" type="text/javascript">
arr = generateArray1();
//printArrFunc(arr);
//arraySplicing();
multiDimArr();
</script>
</body>
</html>