jsarrays.html
<!DOCTYPE html>
<html>
<head>
<title>Javascript example</title>
<meta charset="UTF-8"/>
</head>
<body>
<h1>Javascript arrays</h1>
<h2>Iteration</h2>
<script type="text/javascript">
var a = [0.1, 0.2, 0.3, 0.4];
for(var i in a) document.write("a["+i+"] = "+a[i]+"<br/>");
</script>
<h2>Stack methods</h2>
<script type="text/javascript">
var x = new Array();
x.push("ciao");
x.push("vado");
x.push("e");
x.push("torno");
var y = x.slice(); // copy to y
while(x.length>0) document.write(x.pop()+" ");
</script>
<h2>Queue methods</h2>
<script type="text/javascript">
while(y.length>0) document.write(y.shift()+" ");
</script>
</body>
</html>
jsregexp.html
<!DOCTYPE html>
<html>
<head>
<title>Javascript example</title>
<meta charset="UTF-8"/>
</head>
<body>
<h1>Javascript regular expressions</h1>
<p>Let's start with an arbitrary string:</p>
<script type="text/javascript">
var s = "ciao, sono andata da mia zia";
document.write("<pre>"+s+"</pre>");
</script>
<p>
Now modify it replacing the occurrences
of a regular expression:
</p>
<script type="text/javascript">
var s1 = s.replace(/([nt])a\b/gi,"$1o");
document.write("<pre>"+s1+"</pre>");
</script>
<p>
The regexp <code>/([nt])a\b/gi</code> matches
every word tail composed by a 'n' or a 't' followed
by a 'a'; the <code>String</code> function member
<code>replace</code> substitutes the 'a' in those
occurrences with a 'o'.
</p>
<p> Now if we have:</p>
<script type="text/javascript">
var a = "Weighing 122 pounds and measuring only 77.8 inches long";
document.write("<pre>"+a+"</pre>");
</script>
<p>
And we want to surround all numbers with round
brackets, we will replace every occurrence of
<code>/([\d\.]+)/g</code>, obtaining:
</p>
<script type="text/javascript">
document.write("<pre>"+a.replace(/([\d\.]+)/g,"($1)")+"</pre>");
</script>
</body>
</html>