<html>
<head>
<title>Removing an Array Element</title>
</head>
<body>
<script language="javascript">
<1--
document.writeln("<h1>Removing an Array Element</h1>");
var data ["Monday", "Tuesday", 34, 76.34, "Wednesday"];
// Show the original array
document.write("<p>");
var len data.length;
for (var count 0; count < len; count++) {
document.write(data [count] + ", ");
}
document.writeln("</p>");
// Ask the user what to remove
prompt("Which item shall I remove?", ""); var rem
var tmp new Array(data.length 1);
var count 2 0;
// This loop searches for, and removes a single item for (var count=0; count < len;
count++) {
if (data [count] == rem) {
// do nothing
} else {
tmp [count2] data [count);
count2++;
}
}
data tmp;
// Show the new Array
document.write("<p>");
var len data.length;
for (var count 0; count < len; count++) {
document.write (data [count] + ", ");
}
document.writeln("</p>");
document.close();
//-->
</script>
</body>
</html>
------------------------------------------
<html>
<head>
<title>Concatenating Arrays</title>
</head>
<body>
<script language="javascript">
<1--
document.writeln("<h1>Concatenating Arrays</h1>");
var first ["Monday", "Tuesday", 34, 76.34, "Wednesday"];
var second ["one", "two", "three", 76.9];
var third new Array("an", "object", "array");
var result first.concat (second, third);
// Show the resulting array
document.write("<p>");
var len result.length;
for (var count 0; count< len; count++) {
}
document.write(result [count] + ", ");
document.writeln("</p>");
document.close();
//-->
</script>
</body>
</html>
--------------------------
<html>
<head>
<title>Array Operations</title>
</head>
<body>
<script language="javascript">
<1--
document.writeln("<h1>Array Functions</h1>");
var first, ["Monday", "Tuesday", 34, 76.34, "Wednesday");
document.write("<p>");
document.write(first.join(", "));
document.write("<br>");
first.pop();
document.write(first.join(", "));
document.write("<br>");
first.push("one", "two", "three", 76.9);
document.write(first.join(", "));
document.write("<br>");
first.reverse();
document.write(first.join(", "));
document.write("<br>");
first.shift();
first.shift();
document.write(first.join(", "));
document.writeln("</p>");
document.close();
//-->
</script>
</body>
</html>
-----------------
<html>
<head>
<title>Variables, Functions and Scope</title>
</head>
<body>
<script language="javascript">
var the_var=32;
var tmp=the_var;
var tmp2 = setLocal (17);
document. writeln("<h1>Scope</h1>") ;
document. writeln ("<p>The global is " + the_var) ;
document. writeln ("<br>tmp is " + tmp) ;
document.writeln("<br>tmp2 is "+ tmp2);
document . writeln ("</p>") ;
document.close () ;
function setLocal (num) {
the_var = num;
alert ("tmp is: " + tmp) ;
return (the_var) ;
}
/ / - - >
</script>
</body>
</html>